<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/dxl/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/dxl/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/dxl/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/dxl/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/dxl/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/dxl/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/dxl/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/dxl/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/dxl/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="面试题,">










<meta name="description" content="一、Python基础1、编码 123ASCII 	 英文 1个字节Unicode  英文 中文 都是4个字节UTF-8    ascii  1个字节保存、  欧洲的字符用2个字节保存，  东亚的字符用3个字节保存...  2、注释 12当行注释：# 被注释内容多行注释：&amp;apos;&amp;apos;&amp;apos;被注释内容&amp;apos;&amp;apos;&amp;apos;，或者&amp;quot;&amp;quot;&amp;quot;被注释">
<meta name="keywords" content="面试题">
<meta property="og:type" content="article">
<meta property="og:title" content="python基础">
<meta property="og:url" content="http://yoursite.com/2019/09/20/【内容回顾】03-1python基础/index.html">
<meta property="og:site_name" content="我的快乐时光">
<meta property="og:description" content="一、Python基础1、编码 123ASCII 	 英文 1个字节Unicode  英文 中文 都是4个字节UTF-8    ascii  1个字节保存、  欧洲的字符用2个字节保存，  东亚的字符用3个字节保存...  2、注释 12当行注释：# 被注释内容多行注释：&amp;apos;&amp;apos;&amp;apos;被注释内容&amp;apos;&amp;apos;&amp;apos;，或者&amp;quot;&amp;quot;&amp;quot;被注释">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-05T07:10:57.091Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="python基础">
<meta name="twitter:description" content="一、Python基础1、编码 123ASCII 	 英文 1个字节Unicode  英文 中文 都是4个字节UTF-8    ascii  1个字节保存、  欧洲的字符用2个字节保存，  东亚的字符用3个字节保存...  2、注释 12当行注释：# 被注释内容多行注释：&amp;apos;&amp;apos;&amp;apos;被注释内容&amp;apos;&amp;apos;&amp;apos;，或者&amp;quot;&amp;quot;&amp;quot;被注释">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/dxl/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/09/20/【内容回顾】03-1python基础/">





  <title>python基础 | 我的快乐时光</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/dxl/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的快乐时光</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/dxl/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/dxl/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/dxl/2019/09/20/【内容回顾】03-1python基础/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content>
      <meta itemprop="description" content>
      <meta itemprop="image" content="/dxl/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的快乐时光">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">python基础</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-20T20:05:12+08:00">
                2019-09-20
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/dxl/categories/面试题/" itemprop="url" rel="index">
                    <span itemprop="name">面试题</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/dxl/2019/09/20/【内容回顾】03-1python基础/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/dxl/2019/09/20/【内容回顾】03-1python基础/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、Python基础"><a href="#一、Python基础" class="headerlink" title="一、Python基础"></a>一、Python基础</h2><p>1、编码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ASCII 	 英文 1个字节</span><br><span class="line">Unicode  英文 中文 都是4个字节</span><br><span class="line">UTF-8    ascii  1个字节保存、  欧洲的字符用2个字节保存，  东亚的字符用3个字节保存...</span><br></pre></td></tr></table></figure>

<p>2、注释</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">当行注释：# 被注释内容</span><br><span class="line">多行注释：&apos;&apos;&apos;被注释内容&apos;&apos;&apos;，或者&quot;&quot;&quot;被注释内容&quot;&quot;</span><br></pre></td></tr></table></figure>

<p>3、变量</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#命名规则</span></span><br><span class="line">    <span class="number">1</span>、变量名只能是 字母、数字或下划线的任意组合</span><br><span class="line">    <span class="number">2</span>、变量名的第一个字符不能是数字</span><br><span class="line">    <span class="number">3</span>、以下关键字不能声明为变量名</span><br><span class="line">    [<span class="string">'and'</span>, <span class="string">'as'</span>, <span class="string">'assert'</span>, <span class="string">'break'</span>, <span class="string">'class'</span>, <span class="string">'continue'</span>, <span class="string">'def'</span>, <span class="string">'del'</span>, </span><br><span class="line">    <span class="string">'elif'</span>, <span class="string">'else'</span>, <span class="string">'except'</span>, <span class="string">'exec'</span>, <span class="string">'finally'</span>, <span class="string">'for'</span>, <span class="string">'from'</span>, <span class="string">'global'</span>, <span class="string">'if'</span>, </span><br><span class="line">    <span class="string">'import'</span>, <span class="string">'in'</span>, <span class="string">'is'</span>, <span class="string">'lambda'</span>, <span class="string">'not'</span>, <span class="string">'or'</span>, <span class="string">'pass'</span>, <span class="string">'print'</span>, <span class="string">'raise'</span>, <span class="string">'return'</span>, <span class="string">'try'</span>, <span class="string">'while'</span>, <span class="string">'with'</span>, <span class="string">'yield'</span>]</span><br><span class="line">    <span class="number">4</span>、变量的定义要具有可描述性。</span><br><span class="line">    <span class="number">5</span>、变量名不宜太长</span><br><span class="line">    <span class="number">6</span>、变量名不能是中文</span><br><span class="line">    <span class="number">7</span>、变量名区分大小写</span><br><span class="line"><span class="comment">#两种变量命名方式</span></span><br><span class="line">	驼峰体</span><br><span class="line">        AgeOfOldboy = <span class="number">56</span>（小驼峰）</span><br><span class="line">        NumberOfStudents = <span class="number">80</span>（大驼峰）</span><br><span class="line">    </span><br><span class="line">	下划线（官方推荐）</span><br><span class="line">        age_of_oldboy = <span class="number">56</span>  </span><br><span class="line">        number_of_students = <span class="number">80</span></span><br><span class="line"><span class="comment">#赋值</span></span><br><span class="line">	a = <span class="number">1</span> </span><br><span class="line">    b = a</span><br><span class="line">    a = <span class="number">2</span></span><br><span class="line">    结果：a:<span class="number">2</span> b:<span class="number">1</span></span><br></pre></td></tr></table></figure>

<p>4、常量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">AGE_OF_OLDBOY = 56</span><br><span class="line">全部大写：配置文件中</span><br></pre></td></tr></table></figure>

<p>5、int、bool</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">python2 整型 long整型</span><br><span class="line">python3 长整型</span><br><span class="line">二进制与十进制的转换</span><br><span class="line">print(bin(15))           10----&gt;2</span><br><span class="line">print(int("ob1111",2))   2-----&gt;10</span><br><span class="line"></span><br><span class="line">bool</span><br><span class="line">真   <span class="number">1</span>   <span class="literal">True</span>。</span><br><span class="line">假   <span class="number">0</span>   <span class="literal">False</span></span><br></pre></td></tr></table></figure>

<p>6、str</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#常用方法：</span></span><br><span class="line">	name.capitalize() <span class="comment">#首字母大写</span></span><br><span class="line">    name.swapcase()   <span class="comment">#大小写翻转</span></span><br><span class="line">    msg.title() <span class="comment">#每个单词的首字母大写</span></span><br><span class="line">    ret3 = a1.count(<span class="string">"a"</span>,<span class="number">0</span>,<span class="number">4</span>) <span class="comment"># 可切片数字符串中的元素出现的个数。</span></span><br><span class="line">    ret2 = a1.center(<span class="number">20</span>,<span class="string">"*"</span>)<span class="comment">#内同居中，总长度，空白处填充</span></span><br><span class="line">	upper、lower、<span class="comment">#全部大写、全部小写</span></span><br><span class="line">	startswith、endswith </span><br><span class="line">    split 、rsplit<span class="comment">#分割</span></span><br><span class="line">	index（找不到报错）、find(找不到<span class="number">-1</span>)、</span><br><span class="line">	s.isalpha  <span class="comment">#</span></span><br><span class="line">	join</span><br><span class="line">	replace</span><br><span class="line">    strip rstrip lstrip</span><br><span class="line">    </span><br><span class="line"></span><br><span class="line">str =<span class="string">"asdfgh"</span></span><br><span class="line"><span class="comment">#索引：</span></span><br><span class="line">	str[<span class="number">0</span>]</span><br><span class="line"><span class="comment">#切片：</span></span><br><span class="line">    str[<span class="number">0</span>:<span class="number">-1</span>]</span><br><span class="line">    str[<span class="number">2</span>:<span class="number">5</span>]</span><br><span class="line">    a[<span class="number">0</span>:<span class="number">5</span>:<span class="number">2</span>]</span><br><span class="line">	a[<span class="number">5</span>:<span class="number">0</span>:<span class="number">-2</span>]</span><br><span class="line"><span class="comment">#format格式化输出</span></span><br><span class="line">res=<span class="string">'&#123;&#125; &#123;&#125; &#123;&#125;'</span>.format(<span class="string">'egon'</span>,<span class="number">18</span>,<span class="string">'male'</span>)</span><br><span class="line">res=<span class="string">'&#123;1&#125; &#123;0&#125; &#123;1&#125;'</span>.format(<span class="string">'egon'</span>,<span class="number">18</span>,<span class="string">'male'</span>)</span><br><span class="line">res=<span class="string">'&#123;name&#125; &#123;age&#125; &#123;sex&#125;'</span>.format(sex=<span class="string">'male'</span>,name=<span class="string">'egon'</span>,age=<span class="number">18</span>)</span><br><span class="line"><span class="comment">#is系列</span></span><br><span class="line">print(name.isalnum()) <span class="comment">#字符串由字母或数字组成</span></span><br><span class="line">print(name.isalpha()) <span class="comment">#字符串只由字母组成</span></span><br><span class="line">print(name.isdecimal(解决isdigit的漏洞)()) <span class="comment">#字符串只由数字组成</span></span><br></pre></td></tr></table></figure>

<p>7、list</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">可变数据类型 -----可哈希、查看内存地址（可以原地修改）</span><br><span class="line">有序：支持索引</span><br><span class="line">用于存储不同类型的数据</span><br><span class="line">l =[]</span><br><span class="line">增： l.append(<span class="number">5</span>)   l.insert(<span class="number">0</span>,<span class="string">"7"</span>)   lst.extend([<span class="string">"1"</span>,<span class="string">"2"</span>,<span class="string">"5"</span>]) +</span><br><span class="line">删： l.pop()  l.pop(<span class="number">2</span>)<span class="comment">#  l.remove() l.clear()  del lst  del lst[0]</span></span><br><span class="line">改： l[<span class="number">0</span>]  =<span class="string">"2"</span>  l[<span class="number">1</span>:<span class="number">3</span>] =<span class="string">"111"</span>  <span class="comment">#使用的是连续空间 l[0:5:2] #一一对应</span></span><br><span class="line">查： <span class="keyword">for</span> 索引  切片/(切片+步长)</span><br><span class="line">常用方法：</span><br><span class="line">	len count index(找不到不错，没有find) sort/sort(reverse=true)、reverse(反转)、copy</span><br></pre></td></tr></table></figure>

<p>8、dict</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">字典：无序，可变</span><br><span class="line">键：唯一不可变</span><br><span class="line">值：任意</span><br><span class="line">定义：</span><br><span class="line">dic =&#123;&#125;</span><br><span class="line">dict(k=<span class="number">1</span>,a=<span class="number">10</span>)</span><br><span class="line">dict([(<span class="number">1</span>,<span class="number">2</span>),(<span class="number">1</span>,<span class="number">2</span>),(<span class="number">1</span>,<span class="number">2</span>),])</span><br><span class="line">dic =&#123;&#125;</span><br><span class="line">dic = dic.formkeys(<span class="string">"abc"</span>,[])</span><br><span class="line"></span><br><span class="line">增</span><br><span class="line">dic.setdefault（<span class="string">"key"</span>:<span class="number">1</span>） 有则不变，无则添加</span><br><span class="line">dic[<span class="string">"键"</span>] = 值   </span><br><span class="line">删</span><br><span class="line">dic.pop(<span class="string">"键"</span>) 返回值</span><br><span class="line">dic.popitem()  python3<span class="number">.6</span>默认最后一个，</span><br><span class="line"><span class="keyword">del</span> dic[<span class="string">"键"</span>]</span><br><span class="line">dic.clear()</span><br><span class="line">改：</span><br><span class="line">update  dic2.update(dic)  <span class="comment">#相同的覆盖没有的添加</span></span><br><span class="line">dic[<span class="string">"键"</span>] =值</span><br><span class="line">查</span><br><span class="line">dic.get() <span class="comment">#可以设置返回值</span></span><br><span class="line">dic[<span class="string">"键"</span>] <span class="comment">#没有会报错</span></span><br><span class="line">dic.setdefault(<span class="string">"键"</span>，”值“) <span class="comment">#可以接受返回值1，代表找到，None代表没有找到</span></span><br><span class="line"></span><br><span class="line">keys</span><br><span class="line">values</span><br><span class="line">items </span><br><span class="line">字典的嵌套</span><br></pre></td></tr></table></figure>

<p>9 tuple</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">查：</span><br><span class="line">	索引、切片、切片+步长、for循环</span><br><span class="line">删：</span><br><span class="line">	del</span><br><span class="line">改：</span><br><span class="line">	元组的不可变数据类型不可以修改，可变数据类型可以修改</span><br><span class="line">常用方法：</span><br><span class="line">	count、index</span><br></pre></td></tr></table></figure>

<p>10、集合</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#创建：</span></span><br><span class="line">	  d = &#123;&#125;</span><br><span class="line">	  S = set()</span><br><span class="line">	  S = &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>&#125;</span><br><span class="line">	  S = set([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])</span><br><span class="line"><span class="comment">#增加</span></span><br><span class="line">	add <span class="comment">#有则不变，无则增加</span></span><br><span class="line"><span class="comment">#删除</span></span><br><span class="line">	Pop()    :依次从集合中弹出一个元素,如果集合为空,报错</span><br><span class="line">	Discard(ele) :从集合中删除指定的元素,如果不存在,什么都不执行</span><br><span class="line">	Remove(ele) :从集合中删除指定的元素,如果不存在,报错</span><br><span class="line">	Clear()     :清空</span><br><span class="line">    </span><br><span class="line"><span class="comment">#查</span></span><br><span class="line">	<span class="keyword">for</span> 循环</span><br><span class="line"><span class="comment">#其他常用方法</span></span><br><span class="line">	并集:union（|）、交集:intersection（&amp;）、差集:difference（-）、</span><br><span class="line">    对称差:symmetric_differenc</span><br><span class="line">    Isdisjoint:判断两个集合是否没有交集</span><br><span class="line">	Issubset:判断当前集合是否是后者的子集</span><br><span class="line">	Issuperset:判断后者是否是当前集合的子集</span><br></pre></td></tr></table></figure>

<p>11、深浅copy</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、浅拷贝copy</span><br><span class="line">	可变数据类型与不可变数据类型的内存地址是公用的</span><br><span class="line"><span class="number">2</span>、深拷贝deepcopy</span><br><span class="line">	不可变数据类型是公用的，可变数据类型是重新创建的</span><br></pre></td></tr></table></figure>

<p>12、数据类型的转换</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、int bool str 三者之间可以进行相互转换</span><br><span class="line"><span class="number">2</span>、bool可以与所有类型值进行转换，所有为空的数据类型转化成bool都为Fasle</span><br><span class="line"><span class="number">3</span>、str、list之间可以进行相互转换  list，split join</span><br><span class="line"><span class="number">4</span>、str、之间tuple可以进行相互转换</span><br><span class="line">	str =<span class="string">"asdfggg"</span></span><br><span class="line">	tup =tuple(str) <span class="comment">#('a', 's', 'd', 'f', 'g', 'g', 'g')</span></span><br><span class="line">strs = <span class="string">""</span>.join(tup) <span class="comment">#asdfggg</span></span><br><span class="line">5、dict ----&gt; list，list步能转换成list</span><br><span class="line"><span class="number">6</span>、set 可以转换成list list 不可以转换成set</span><br></pre></td></tr></table></figure>

<p>13、数据类型的分类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">存值个数：</span><br><span class="line">	原子类型：数字、字符串</span><br><span class="line">	容器类型： 列表 元组 字典</span><br><span class="line">可变与不可变：</span><br><span class="line">	可变：列表、字典</span><br><span class="line">	不可变：数字、字符串、元组、布尔值</span><br><span class="line">访问顺序：</span><br><span class="line">	直接访问：数字</span><br><span class="line">	顺序访问：字符串、列表、元组</span><br><span class="line">	key值访问：字典</span><br></pre></td></tr></table></figure>

<p>14、数据类型的小坑</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、tuple只有一个元素</span><br><span class="line">	tu1 = (<span class="string">'dxl'</span>) <span class="comment">#alex &lt;class 'str'&gt;</span></span><br><span class="line"><span class="number">2</span>、列表的复值</span><br><span class="line">    l1 = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">    l2 = l1</span><br><span class="line">    l3 = l2</span><br><span class="line">    l1.append(<span class="number">666</span>)</span><br><span class="line">    l2.append(<span class="number">111</span>)</span><br><span class="line">    l3.append(<span class="number">333</span>)</span><br><span class="line">    print(l1)   <span class="comment">#[1, 2, 3, 666, 111, 333]</span></span><br><span class="line">    print(l2)   <span class="comment">#[1, 2, 3, 666, 111, 333]</span></span><br><span class="line">    print(l3)  <span class="comment">#[1, 2, 3, 666, 111, 333]</span></span><br><span class="line"><span class="number">3</span>、字典的fromkeys</span><br><span class="line">    dic = dict.fromkeys(<span class="string">'abcd'</span>,[])</span><br><span class="line">    dic[<span class="string">'a'</span>].append(<span class="number">666</span>)  <span class="comment">#&#123;'a': [666], 'b': [666], 'c': [666], 'd': [666]&#125;</span></span><br><span class="line"><span class="number">4</span>、删除一个列表的索引为奇数的元素时</span><br><span class="line">	first：切片</span><br><span class="line">    second：通过第三个列表、</span><br><span class="line">    third:倒叙删除</span><br><span class="line"><span class="number">5</span>、将字典中的key中含有k元素的所有键值对删除.</span><br><span class="line">	<span class="number">1</span>、循环字典，将字典的键加入一个列表</span><br><span class="line">    <span class="number">2</span>、循环列表，判断列表中的元素是否含有“k”,有则删除元素对应的字典中的键值对</span><br></pre></td></tr></table></figure>

<p>10、程序交互</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">name = input(<span class="string">"请输入用户名："</span>)</span><br><span class="line">print(name)</span><br></pre></td></tr></table></figure>

<p>11、格式化输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">%s (%d %i） </span><br><span class="line">format（字符串里面有详解）</span><br><span class="line"><span class="string">f"<span class="subst">&#123;a&#125;</span>heoll<span class="subst">&#123;b&#125;</span>"</span></span><br></pre></td></tr></table></figure>

<p>12、转义</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">%%</span><br></pre></td></tr></table></figure>

<p>13、基本运算符</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、算数运算 + -  * / //（商的整数部分）  %（余数） **（求幂）</span><br><span class="line"><span class="number">2</span>、比较运算 == ！= &lt;&gt;  &gt; &lt; &gt;= &lt;=</span><br><span class="line"><span class="number">3</span>、复制运算  = += -=  *= /= %=  **=  // =</span><br><span class="line"><span class="number">4</span>、逻辑运算  <span class="keyword">and</span> <span class="keyword">or</span> <span class="keyword">not</span></span><br><span class="line">	x <span class="keyword">and</span> y </span><br><span class="line">	<span class="keyword">and</span>  x 为 false 返回 false 否则返回 y</span><br><span class="line">	<span class="keyword">or</span>   x 为 true 返回 true   否则返回 y</span><br><span class="line">	<span class="keyword">not</span> x </span><br><span class="line">	<span class="keyword">not</span>  x 为 true 返回 false  x 为false 返回true</span><br><span class="line"><span class="number">5</span>、成员元算  </span><br><span class="line">	<span class="keyword">in</span>    <span class="keyword">not</span> <span class="keyword">in</span></span><br><span class="line"><span class="number">6</span>、运算符的优先级  </span><br><span class="line">	** 、~+- 、 */%//、  +- 、&gt;&gt;&lt;&lt;（右移、左移） 、&amp;  、^| 、 &lt;=&lt;&gt;&gt;=</span><br><span class="line">	&lt;&gt; == ！=    、 = %==   、<span class="keyword">is</span> <span class="keyword">is</span> <span class="keyword">not</span> 、 <span class="keyword">in</span> notin 、<span class="keyword">not</span> <span class="keyword">and</span> <span class="keyword">or</span></span><br></pre></td></tr></table></figure>

<p>14、流程控制</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、单分支一</span><br><span class="line"><span class="keyword">if</span> 条件:</span><br><span class="line">    满足条件后要执行的代码</span><br><span class="line"><span class="number">2</span>、双分支</span><br><span class="line"><span class="keyword">if</span> 条件:</span><br><span class="line">	满足条件执行代码</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">	<span class="keyword">if</span>条件不满足就走这段</span><br><span class="line"><span class="number">3</span>、多分支一（一个条件执行）</span><br><span class="line">    <span class="keyword">if</span> 条件:</span><br><span class="line">    	满足条件执行代码</span><br><span class="line">    <span class="keyword">elif</span> 条件:</span><br><span class="line">    	上面的条件不满足就走这个</span><br><span class="line">    <span class="keyword">elif</span> 条件:</span><br><span class="line">    	上面的条件不满足就走这个</span><br><span class="line">    <span class="keyword">elif</span> 条件:</span><br><span class="line">    	上面的条件不满足就走这个 </span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">   	 上面所有的条件不满足就走这段</span><br><span class="line"><span class="number">5</span>、多分支二（可能一个条件都不执行）</span><br><span class="line"><span class="keyword">if</span> 条件:</span><br><span class="line">	满足条件执行代码</span><br><span class="line"><span class="keyword">elif</span> 条件:</span><br><span class="line">	上面的条件不满足就走这个</span><br><span class="line"><span class="keyword">elif</span> 条件:</span><br><span class="line">	上面的条件不满足就走这个</span><br><span class="line"><span class="keyword">elif</span> 条件:</span><br><span class="line">	上面的条件不满足就走这个</span><br><span class="line"><span class="number">6</span>、双<span class="keyword">if</span>（两个条件都有可能执行）</span><br><span class="line"><span class="keyword">if</span> 条件:</span><br><span class="line">    满足条件后要执行的代码</span><br><span class="line"><span class="keyword">if</span> 条件:</span><br><span class="line">    满足条件后要执行的代码</span><br></pre></td></tr></table></figure>

<p>15、循环语句</p>
<p>1、while循环</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> <span class="number">1</span>:</span><br><span class="line">	循环体</span><br><span class="line"><span class="number">1</span>、<span class="keyword">continue</span> 结束本次循环进行下次循环</span><br><span class="line"><span class="number">2</span>、<span class="keyword">break</span>当前循环</span><br><span class="line"></span><br><span class="line">count = <span class="number">0</span></span><br><span class="line"><span class="keyword">while</span> count &lt;= <span class="number">5</span> :</span><br><span class="line">    count += <span class="number">1</span></span><br><span class="line">    print(<span class="string">"Loop"</span>,count)</span><br><span class="line"></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">"循环正常执行完啦"</span>)<span class="comment">#程序正常执行完执行这句话</span></span><br></pre></td></tr></table></figure>

<p>2、for循环</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">循环的对象：可迭代</span><br><span class="line">enumerate</span><br><span class="line">range</span><br><span class="line">break</span><br><span class="line">contiue</span><br></pre></td></tr></table></figure>

<p>16、代码块</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1、交互方式输入的每个命令都是一个代码块</span><br><span class="line">2、一个模块，一个函数，一个类，一个文件等都是一个代码块</span><br><span class="line">3、一个文件中的两个函数是两个代码块</span><br></pre></td></tr></table></figure>

<p>17、代码块的缓存机制</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">定义：</span><br><span class="line">	Python在执行同一个代码块的初始化对象的命令时，会检查是否其值是否已经存在，如果存在，会将其重用</span><br><span class="line">代码块的缓存机制： </span><br><span class="line">	int（float），str，bool。</span><br><span class="line">	int(float):任何数字在同一代码块下都会复用。</span><br><span class="line">	bool:True和False在字典中会以1，0方式存在，并且复用。</span><br><span class="line">	str：几乎所有的字符串都会符合缓存机制，具体规定如下（了解即可！）：</span><br><span class="line">1、非乘法得到的字符串都满足代码块的缓存机制：</span><br><span class="line">2、乘数为1时，任何字符串满足代码块的缓存机制：</span><br><span class="line">3、乘数&gt;=2时：仅含大小写字母，数字，下划线，总长度&lt;=20，满足代码块的缓存机制</span><br><span class="line">优点：</span><br><span class="line">	1、能够提高一些字符串，整数处理人物在时间和空间上的性能；</span><br><span class="line">	2、需要值相同的字符串，整数的时候，直接从‘字典’中取出复用，避免频繁的创建和销毁，提升效率，节约内存</span><br></pre></td></tr></table></figure>

<p>18、小数据池</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python做的一个优化，将~5-256的整数，和一定规则的字符串，放在一个‘池’（容器，或者字典）中，无论程序中那些变量指向这些范围内的整数或者字符串，那么他直接在这个‘池’中引用</span><br></pre></td></tr></table></figure>

<p>19、文件操作</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、打开文件的方式</span><br><span class="line">	f=open(<span class="string">'a.txt'</span>,<span class="string">'r'</span>,encoding=<span class="string">'utf-8'</span>) <span class="comment">#默认打开模式就为r</span></span><br><span class="line">	<span class="keyword">with</span> open(<span class="string">'a.txt'</span>,<span class="string">'w'</span>) <span class="keyword">as</span> f:</span><br><span class="line">	<span class="keyword">with</span> open(<span class="string">'a.txt'</span>,<span class="string">'r'</span>) <span class="keyword">as</span> read_f,open(<span class="string">'b.txt'</span>,<span class="string">'w'</span>) <span class="keyword">as</span> write_f:</span><br><span class="line"><span class="number">2</span>、模式</span><br><span class="line">    r ，只读模式【默认模式，文件必须存在，不存在则抛出异常】</span><br><span class="line">    w，只写模式【不可读；不存在则创建；存在则清空内容】</span><br><span class="line">    a， 只追加写模式【不可读；不存在则创建；存在则只追加内容】</span><br><span class="line"></span><br><span class="line">	rb </span><br><span class="line">    wb</span><br><span class="line">    ab</span><br><span class="line">    </span><br><span class="line">    r+， 读写【可读，可写】</span><br><span class="line">	w+，写读【可写，可读】   </span><br><span class="line">	a+， 写读【可写，可读】 <span class="comment">#读取不到东西</span></span><br><span class="line">	</span><br><span class="line">	r+b， 读写【可读，可写】</span><br><span class="line">	w+b，写读【可写，可读】</span><br><span class="line">	a+b， 写读【可写，可读】</span><br><span class="line"><span class="number">3</span>、read()</span><br><span class="line">	<span class="number">1</span>)read(<span class="number">3</span>)文件打开方式为文本模式时，代表读取<span class="number">3</span>个字符</span><br><span class="line">	<span class="number">2</span>)文件打开方式为b模式时，代表读取<span class="number">3</span>个字节</span><br><span class="line"><span class="number">4</span>、  seek()</span><br><span class="line">	 seek(<span class="number">0</span>,<span class="number">0</span>)  头部seek(<span class="number">0</span>,<span class="number">1</span>) 当前位置  seek(<span class="number">0</span>,<span class="number">2</span>) 尾部</span><br><span class="line">     seek(<span class="number">3</span>)</span><br><span class="line">     句柄.tell()</span><br><span class="line">	seek有三种移动方式<span class="number">0</span>，<span class="number">1</span>，<span class="number">2</span>，其中<span class="number">1</span>和<span class="number">2</span>必须在b模式下进行，但无论哪种模式，都是以bytes为单位移动的</span><br><span class="line"><span class="number">5</span>、truncate（）</span><br><span class="line">	不能用w或w+等方式打开，因为那样直接清空文件了，所以truncate要在r+或a或a+等模式下测试效果。</span><br><span class="line"><span class="number">6</span>、文件的修改：</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'a.txt'</span>) <span class="keyword">as</span> read_f,open(<span class="string">'.a.txt.swap'</span>,<span class="string">'w'</span>) <span class="keyword">as</span> write_f:</span><br><span class="line">    <span class="keyword">for</span> line <span class="keyword">in</span> read_f:</span><br><span class="line">        line=line.replace(<span class="string">'lihua'</span>,<span class="string">'SB'</span>)</span><br><span class="line">        write_f.write(line)</span><br><span class="line"></span><br><span class="line">os.remove(<span class="string">'a.txt'</span>)</span><br><span class="line">os.rename(<span class="string">'.a.txt.swap'</span>,<span class="string">'a.txt'</span>)</span><br></pre></td></tr></table></figure>

<h2 id="二、函数"><a href="#二、函数" class="headerlink" title="二、函数"></a>二、函数</h2><h2 id="2-1概念"><a href="#2-1概念" class="headerlink" title="2.1概念"></a>2.1概念</h2><p>1、什么是函数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">就是把代码分装起来的过程</span><br></pre></td></tr></table></figure>

<p>2、函数的返回值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1、没有返回值   不写return</span><br><span class="line">2、只写ruturn  return none</span><br><span class="line">3、一个返回值   return &quot;&quot;</span><br><span class="line">4、返回多个值  return 1,2,3</span><br><span class="line">5、返回多个值的接受  一个变量或多个变量</span><br></pre></td></tr></table></figure>

<p>3、函数的参数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">考点：</span><br><span class="line">	看代码写结果</span><br><span class="line">	默认参数为可变的数据类型</span><br><span class="line">函数的参数</span><br><span class="line">	实参：位置、关键字参数、混合参数</span><br><span class="line">    形参：位置参数  仅限关键字参数 默认参数 动态参数 </span><br><span class="line">	形参的位置 func（a,b,*args,c,sex=<span class="string">"nan"</span>,**kwargs)</span><br><span class="line">默认参数：可变的数据类型</span><br></pre></td></tr></table></figure>

<p>4、函数的命名空间、取值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">空间：</span><br><span class="line">	内置命名空间  python解释器为我们提供的名字</span><br><span class="line">	全局部命名空间   创建的存储“变量名与值的关系”的空间</span><br><span class="line">	局部命名空间   函数的运行中开辟的临时的空间</span><br><span class="line">加载顺序：</span><br><span class="line">	内置命名空间(程序运行前加载)-&gt;全局命名空间(程序运行中：从上到下加载)-&gt;局部命名空间(程序运行中：调用时才加载)	</span><br><span class="line">取值顺序：</span><br><span class="line">	局部  全局 内置</span><br></pre></td></tr></table></figure>

<p>5、作用域</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">全局作用域  内置名称空间、全局名称空间，在整个文件的任意位置都能被引用、全局有效</span><br><span class="line">局部作用域  局部名称空间，只能在局部范围内生效</span><br><span class="line"><span class="keyword">global</span> <span class="keyword">nonlocal</span></span><br><span class="line"><span class="keyword">global</span>的作用：</span><br><span class="line">	<span class="number">1</span>、改变全局变量</span><br><span class="line">    <span class="number">2</span>、声明全局变量</span><br><span class="line"><span class="keyword">nonlocal</span>:</span><br><span class="line">    <span class="number">1</span>、外层函数非全局必须有这个变量</span><br><span class="line">    <span class="number">2</span>、在内部函数声明<span class="keyword">nonlocal</span>变量之前不能再出现同名变量</span><br><span class="line">    <span class="number">3</span>、内部修改这个变量如果想在外部有这个变量的第一层函数中生效</span><br><span class="line">    </span><br><span class="line">注意事项：</span><br><span class="line">	<span class="number">1</span>、在函数内部可以改变全局作用域中字典中键的值</span><br></pre></td></tr></table></figure>

<p>6、函数的嵌套</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1定义：定义在内部的函数无法直接在全局被调用</span><br><span class="line">一层嵌套、多层嵌套</span><br></pre></td></tr></table></figure>

<p>6、函数名的本质</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、函数名的本质是函数的内存地址</span><br><span class="line"><span class="number">2</span>、可以被当作容器类型的元素</span><br><span class="line"><span class="number">3</span>、可以当作函数的参数和返回值</span><br></pre></td></tr></table></figure>

<p>7*的用法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1、* 处理剩余元素</span><br><span class="line">	a,*b,c=[1,2,3,4,5,6]</span><br><span class="line">	a,*b,c =range(7)</span><br><span class="line">2、、</span><br></pre></td></tr></table></figure>

<p>8、函数名的应用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1、函数名可以赋值</span><br><span class="line">2、函数名可以当做容器类元素</span><br><span class="line">3、可以当作函数的参数和返回值</span><br></pre></td></tr></table></figure>

<p>9、闭包</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">1、原理：</span><br><span class="line">	1、内层函数对外层函数非全局变量的引用</span><br><span class="line">	2、存在嵌套函数中</span><br><span class="line">	3、内层函数的函数名必须作为返回值返回</span><br><span class="line">2、作用：</span><br><span class="line">	引用函数内部的变量，保证数据的安全，</span><br><span class="line">3、判断闭包函数的方法：__closure__</span><br><span class="line">	 返回值为none时，不是闭包函数</span><br><span class="line">3、自由变量</span><br><span class="line">	被引用的变量称为自由变量，不会随着函数的结束而消失</span><br></pre></td></tr></table></figure>

<p>10、生成器</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、生成器的本质是迭代器</span><br><span class="line"><span class="number">2</span>、与迭代器的区别：</span><br><span class="line">	生成器：自己可以通过代码构建</span><br><span class="line">	迭代器：python直接提供的的、通过iter转换</span><br><span class="line"><span class="number">3</span>、构建生成器的方式;</span><br><span class="line">	通过生成函数构建（<span class="keyword">yield</span>）</span><br><span class="line">    生成器推导式</span><br><span class="line">    有一部是python给你提供的map</span><br><span class="line"><span class="number">4</span>、<span class="keyword">yield</span>：</span><br><span class="line">	挂起</span><br><span class="line">    <span class="keyword">yield</span> 后面可以加返回值</span><br><span class="line"><span class="number">5</span>、send</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">generator</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="number">123</span>)</span><br><span class="line">    content = <span class="keyword">yield</span> <span class="number">1</span>  <span class="comment">#content 用于接收send的传值</span></span><br><span class="line">    print(<span class="string">'======='</span>,content)</span><br><span class="line">    print(<span class="number">456</span>)</span><br><span class="line">    <span class="keyword">yield</span> <span class="number">2</span></span><br><span class="line"></span><br><span class="line">g = generator()</span><br><span class="line">ret = g.__next__()</span><br><span class="line"><span class="comment"># print('***',ret)   # ***1</span></span><br><span class="line">ret = g.send(<span class="string">'hello'</span>)   <span class="comment">#send的效果和next一样 =====hello</span></span><br><span class="line"><span class="comment"># print('***',ret)  # ***2</span></span><br><span class="line"><span class="comment">#注意事项：</span></span><br><span class="line"> 	<span class="comment">#第一次使用生成器的时候 是用next获取下一个值</span></span><br><span class="line">    <span class="comment"># 最后一个yield不能接受外部的值/</span></span><br><span class="line"><span class="number">6</span>、<span class="keyword">yield</span> <span class="keyword">from</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">gen1</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">for</span> c <span class="keyword">in</span> <span class="string">'AB'</span>:</span><br><span class="line">        <span class="keyword">yield</span> c</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">3</span>):</span><br><span class="line">        <span class="keyword">yield</span> i</span><br><span class="line"></span><br><span class="line">print(list(gen1()))</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">gen2</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">yield</span> <span class="keyword">from</span> <span class="string">'AB'</span></span><br><span class="line">    <span class="keyword">yield</span> <span class="keyword">from</span> range(<span class="number">3</span>)</span><br><span class="line"></span><br><span class="line">print(list(gen2()))</span><br></pre></td></tr></table></figure>

<p>11、装饰器</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br></pre></td><td class="code"><pre><span class="line">*****：</span><br><span class="line">	手写装饰器、装饰器模拟登陆验证、装饰器的执行流程、多个装饰器装饰一个函数</span><br><span class="line"><span class="number">1</span>、装饰器;</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wrapper</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">        <span class="string">"""函数执行之前的代码"""</span></span><br><span class="line">        ret = func(*args,**kwargs)</span><br><span class="line">        <span class="string">"""函数执行之后的代码"""</span></span><br><span class="line">        <span class="keyword">return</span> ret </span><br><span class="line">    <span class="keyword">return</span> inner</span><br><span class="line"><span class="number">2</span>、装饰器的执行流程</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wrapper1</span><span class="params">(func)</span>:</span></span><br><span class="line">    print(wrapper1)</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner1</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">        print(<span class="string">"before inner1"</span>)</span><br><span class="line">        ret  = func(*args,**kwargs)</span><br><span class="line">        print(<span class="string">"after inner1"</span>)</span><br><span class="line">        <span class="keyword">return</span> ret</span><br><span class="line">    <span class="keyword">return</span> inner1</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wrapper2</span><span class="params">(func)</span>:</span></span><br><span class="line">    print(wrapper2)</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner2</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">        print(<span class="string">"before inner2"</span>)</span><br><span class="line">        ret  = func(*args,**kwargs)</span><br><span class="line">        print(<span class="string">"after inner2"</span>)</span><br><span class="line">        <span class="keyword">return</span> ret</span><br><span class="line">    <span class="keyword">return</span> inner2</span><br><span class="line"></span><br><span class="line"><span class="meta">@wrapper2   # inner1 ==wrapper2(inner2) 2  inner1 = inner2</span></span><br><span class="line"><span class="meta">@wrapper1   #func=wrapper1(func) func = inner2</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">"hello world"</span>)</span><br><span class="line">func()</span><br><span class="line"></span><br><span class="line"><span class="number">3</span>、完整版的装饰器</span><br><span class="line"><span class="keyword">from</span> functools <span class="keyword">import</span> wraps</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">out</span><span class="params">(flag)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">deco</span><span class="params">(func)</span>:</span></span><br><span class="line"><span class="meta">        @wraps(func) #加在最内层函数正上方</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">wrapper</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">            <span class="keyword">if</span> flag:</span><br><span class="line">                print(<span class="string">"函数执行前"</span>)</span><br><span class="line">            ret = func(*args,**kwargs)</span><br><span class="line">            <span class="keyword">if</span> flag:</span><br><span class="line">                print(<span class="string">"函数执行后"</span>)</span><br><span class="line">            <span class="keyword">return</span> ret</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> wrapper</span><br><span class="line">    <span class="keyword">return</span> deco</span><br><span class="line"></span><br><span class="line"><span class="meta">@out(False)</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">index</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="string">'''哈哈哈哈'''</span></span><br><span class="line">    print(<span class="string">'from index'</span>)</span><br><span class="line">index()</span><br><span class="line"><span class="number">4</span>、多个装饰器装饰一个函数</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wrapper1</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner1</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">        print(<span class="string">"before inner1"</span>)</span><br><span class="line">        ret  = func(*args,**kwargs)</span><br><span class="line">        print(<span class="string">"after inner1"</span>)</span><br><span class="line">        <span class="keyword">return</span> ret</span><br><span class="line">    <span class="keyword">return</span> inner1</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wrapper2</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner2</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">        print(<span class="string">"before inner2"</span>)</span><br><span class="line">        ret  = func(*args,**kwargs)</span><br><span class="line">        print(<span class="string">"after inner2"</span>)</span><br><span class="line">        <span class="keyword">return</span> ret</span><br><span class="line">    <span class="keyword">return</span> inner2</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">wrapper3</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">inner3</span><span class="params">(*args,**kwargs)</span>:</span></span><br><span class="line">        print(<span class="string">"before inner3"</span>)</span><br><span class="line">        ret  = func(*args,**kwargs)</span><br><span class="line">        print(<span class="string">"after inner3"</span>)</span><br><span class="line">        <span class="keyword">return</span> ret</span><br><span class="line">    <span class="keyword">return</span> inner3</span><br><span class="line"></span><br><span class="line"><span class="meta">@wrapper3</span></span><br><span class="line"><span class="meta">@wrapper2</span></span><br><span class="line"><span class="meta">@wrapper1</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">"hello world"</span>)</span><br><span class="line">func()</span><br><span class="line">执行结果：</span><br><span class="line"><span class="string">"""</span></span><br><span class="line"><span class="string">before inner3</span></span><br><span class="line"><span class="string">before inner2</span></span><br><span class="line"><span class="string">before inner1</span></span><br><span class="line"><span class="string">hello world</span></span><br><span class="line"><span class="string">after inner1</span></span><br><span class="line"><span class="string">after inner2</span></span><br><span class="line"><span class="string">after inner3</span></span><br><span class="line"><span class="string">"""</span></span><br></pre></td></tr></table></figure>

<p>12、迭代</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">考点;</span><br><span class="line">	原理的东西较多</span><br><span class="line">可迭代对象：含有__iter_</span><br><span class="line">		  可迭代的数据类型：字符串、列表、元组、字典、集合</span><br><span class="line">		  可迭代协议：内部实现了__iter 方法</span><br><span class="line">		  缺点;占用内存</span><br><span class="line">		  优点：直观，操作方便</span><br><span class="line">迭代器：   含有__iter__  __next__</span><br><span class="line">		  优势：节省内存、惰性机制、不走回头路</span><br><span class="line">		  缺点：操作方法较少、</span><br><span class="line">          时间换取空间</span><br><span class="line">注意事项：range 是一个迭代对象，不是迭代器</span><br></pre></td></tr></table></figure>

<p>13、推导式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">构建[1,,4,9...,100]</span><br><span class="line">	循环模式：</span><br><span class="line">	[i*i for i in range(10)]</span><br><span class="line">	筛选模式：</span><br></pre></td></tr></table></figure>

<p>15、内置函数、匿名函数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、匿名函数</span><br><span class="line">	函数名 = <span class="keyword">lambda</span> 参数 ：返回值</span><br><span class="line">	<span class="comment">#参数可以有多个，用逗号隔开</span></span><br><span class="line"></span><br><span class="line">max min fliter map zip sorted reduce</span><br><span class="line">zip和reduce的用法：</span><br><span class="line"><span class="comment"># a =[1,2,3,4]</span></span><br><span class="line"><span class="comment"># b =["a","b","c","d","e"]</span></span><br><span class="line"><span class="comment"># c =zip(a,b)</span></span><br><span class="line"><span class="comment"># print(list(c))</span></span><br><span class="line"><span class="comment">#redeuce</span></span><br><span class="line"><span class="keyword">from</span> functools <span class="keyword">import</span> reduce</span><br><span class="line">l  = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,]</span><br><span class="line">c =reduce(<span class="keyword">lambda</span> x,y:x+y,l,<span class="number">10</span>)</span><br><span class="line">print(c)</span><br></pre></td></tr></table></figure>

<p>16、递归函数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、递归的定义;</span><br><span class="line">	就是在一个函数里再调用这个函数本身</span><br><span class="line"><span class="number">2</span>、递归的最大深度：</span><br><span class="line">	计算规定的是<span class="number">1000</span>，实测的是<span class="number">997</span>、<span class="number">998</span></span><br><span class="line"><span class="number">3</span>、修改递归最大深度</span><br><span class="line">	<span class="keyword">import</span> sys</span><br><span class="line">	print(sys.setrecursionlimit(<span class="number">100000</span>))</span><br><span class="line"><span class="number">4</span>、堆栈实现三级菜单</span><br><span class="line">	l = [menu]</span><br><span class="line">    <span class="keyword">while</span> l:</span><br><span class="line">        <span class="keyword">for</span> key <span class="keyword">in</span> l[<span class="number">-1</span>]:print(key)</span><br><span class="line">        k = input(<span class="string">'input&gt;&gt;'</span>).strip()   <span class="comment"># 北京</span></span><br><span class="line">        <span class="keyword">if</span> k <span class="keyword">in</span> l[<span class="number">-1</span>].keys() <span class="keyword">and</span> l[<span class="number">-1</span>][k]:l.append(l[<span class="number">-1</span>][k])</span><br><span class="line">        <span class="keyword">elif</span> k == <span class="string">'b'</span>:l.pop()</span><br><span class="line">        <span class="keyword">elif</span> k == <span class="string">'q'</span>:<span class="keyword">break</span></span><br><span class="line"><span class="number">4</span>、递归函数实现三级菜单</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">threeLM</span><span class="params">(dic)</span>:</span></span><br><span class="line">    <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">        <span class="keyword">for</span> k <span class="keyword">in</span> dic:print(k)</span><br><span class="line">            key = input(<span class="string">'input&gt;&gt;'</span>).strip()</span><br><span class="line">            <span class="keyword">if</span> key == <span class="string">'b'</span> <span class="keyword">or</span> key == <span class="string">'q'</span>:<span class="keyword">return</span> key</span><br><span class="line">            <span class="keyword">elif</span> key <span class="keyword">in</span> dic.keys() <span class="keyword">and</span> dic[key]:</span><br><span class="line">                ret = threeLM(dic[key])</span><br><span class="line">                <span class="keyword">if</span> ret == <span class="string">'q'</span>: <span class="keyword">return</span> <span class="string">'q'</span></span><br><span class="line">threeLM(menu)</span><br></pre></td></tr></table></figure>

<h2 id="三、模块"><a href="#三、模块" class="headerlink" title="三、模块"></a>三、模块</h2><p>1、列举已使用过得内置模块</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">os  time datetime sys  hashlib logging json pickle re uuid socket  collections  random  threading  multiprocess  functions</span><br></pre></td></tr></table></figure>

<p>2、列举学过的第三方模块</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">request djanjo flask pillow pandas numpy  gevent greenlet redis pymysql ...</span><br><span class="line">xlxm  beautifusoup</span><br></pre></td></tr></table></figure>

<h2 id="四、面向对象"><a href="#四、面向对象" class="headerlink" title="四、面向对象"></a>四、面向对象</h2><h2 id="4-1概念"><a href="#4-1概念" class="headerlink" title="4.1概念"></a>4.1概念</h2><p>1、面向对象和面向过程：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">1、面向过程：</span><br><span class="line">	思想：，过程即解决问题的步骤</span><br><span class="line">	优点：极大的降低了写程序的复杂度，只需要顺着要执行的步骤，堆叠代码即可</span><br><span class="line">	缺点：一套流水线或者流程就是用来解决一个问题，代码牵一发而动全身</span><br><span class="line">	应用场景：一旦完成基本很少改变的场景</span><br><span class="line">2、面向对象：</span><br><span class="line">	思想：上帝式思维</span><br><span class="line">	优点：解决了程序的扩展性。对某一个对象单独修改，会立刻反映到整个体系中</span><br><span class="line">	缺点：可控性差，无法向面向过程的程序设计流水线式的可以很精准的预测问题的处理流程与结果</span><br><span class="line">	应用场景：需求经常变化的软件，一般需求的变化都集中在用户层，互联网应用，企业内部软件，大型游戏</span><br><span class="line">3、相关名词：</span><br><span class="line">    类：具有相同特征的一类事物(人、狗、老虎)</span><br><span class="line">    对象／实例：具体的某一个事物（隔壁阿花、楼下旺财）</span><br><span class="line">    实例化：类——&gt;对象的过</span><br></pre></td></tr></table></figure>

<p>2、类、和对象</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、类的声明和属性引用</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Person</span>:</span> </span><br><span class="line">    role = <span class="string">'person'</span> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">walk</span><span class="params">(self)</span>:</span>  </span><br><span class="line">        print(<span class="string">"person is walking..."</span>)</span><br><span class="line"></span><br><span class="line">print(Person.role) <span class="comment">#查看类属性</span></span><br><span class="line">print(Person.walk) <span class="comment">#查看类方法</span></span><br><span class="line">dxl = Person（） <span class="comment">#实例化</span></span><br><span class="line">dxl.name  <span class="comment">#调用属性</span></span><br><span class="line">dxl.walk() <span class="comment">#调用方法</span></span><br><span class="line">补充：</span><br><span class="line">类名.__name__<span class="comment"># 类的名字(字符串)</span></span><br><span class="line">类名.__doc__<span class="comment"># 类的文档字符串</span></span><br><span class="line">类名.__base__<span class="comment"># 类的第一个父类(在讲继承时会讲)</span></span><br><span class="line">类名.__bases__<span class="comment"># 类所有父类构成的元组(在讲继承时会讲)</span></span><br><span class="line">类名.__dict__<span class="comment"># 类的字典属性</span></span><br><span class="line">类名.__module__<span class="comment"># 类定义所在的模块</span></span><br><span class="line">类名.__class__<span class="comment"># 实例对应的类(仅新式类中)</span></span><br><span class="line">总结：</span><br><span class="line">     <span class="number">1.</span>类名可以调用所有定义在类中的名字</span><br><span class="line">        变量</span><br><span class="line">        函数名 </span><br><span class="line">     <span class="number">2</span>、对象名 可以调用所有diao定义在对象中的属性</span><br><span class="line">        在init函数中和self相关的</span><br><span class="line">        调用函数的，且调用函数的时候，会把当前的对象当做第一个参数传递给self</span><br><span class="line">     <span class="number">3</span>、self 在实例化时自动将对象/实例本身传给__init__的第一个参数.</span><br><span class="line">     <span class="number">4</span>、类名（）就是实例化</span><br><span class="line">     <span class="number">5</span>、对象名.对象的属性<span class="number">1</span> 调用属性</span><br><span class="line">     <span class="number">6</span>、对象名.方法（）调用方法</span><br></pre></td></tr></table></figure>

<p>3、对象的交互</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在一个对象的方法中传入另一个对象的实例</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Person</span>:</span></span><br><span class="line">    role = <span class="string">'person'</span> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, name, aggressivity, life_value)</span>:</span></span><br><span class="line">        self.life_value = life_value  </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">attack</span><span class="params">(self,dog)</span>:</span></span><br><span class="line">        dog.life_value -= self.aggressivity</span><br></pre></td></tr></table></figure>

<p>4、类命名空间与对象、实例的命名空间</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、创建一个类就会创建一个类的名称空间，用来存储类中定义的所有名字，这些名字称为类的属性</span><br><span class="line"><span class="number">2</span>、创建一个对象/实例就会创建一个对象/实例的名称空间，存放对象/实例的名字</span><br><span class="line"><span class="number">3</span>、类有两种属性：静态属性和动态属性</span><br><span class="line">    静态属性就是直接在类中定义的变量</span><br><span class="line">    动态属性就是定义在类中的方法</span><br><span class="line"><span class="number">4</span>、类的静态属性是共享给所有对象的</span><br><span class="line">   类的动态属性是绑定到所有对象的</span><br></pre></td></tr></table></figure>

<p>2、实例化对象的过程</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1. 先调用object类__new__方法在内存中开辟一个对象空间,并返回.</span><br><span class="line">2. 自动执行__init__方法,并将对象空间传给self.</span><br><span class="line">3. 在__init__方法里面给其封装属性.</span><br></pre></td></tr></table></figure>

<p>3、类组合</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">在一个类中以另外一个类的对象作为数据属性</span><br><span class="line"><span class="comment">#计算圆环的面积</span></span><br></pre></td></tr></table></figure>

<p>3、实例化对象发生了三件事</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1、先调用object的__new__方法在内存中开辟空间并返回</span><br><span class="line">2、自动执行__init__方法并将空间对象创给self</span><br><span class="line">3、在 __init__方法里面给其封装属性</span><br></pre></td></tr></table></figure>

<p>4、继承</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、定义：</span><br><span class="line">	新建的类可以继承一个或多个父类，父类又可称为基类或超类，新建的类称为派生类或子类</span><br><span class="line"><span class="number">2</span>、单继承</span><br><span class="line">	对象如何既执行子类的方法,又执行父类的方法</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">A</span>：   </span></span><br><span class="line"><span class="class">        <span class="title">def</span> <span class="title">func</span><span class="params">(self)</span>:</span></span><br><span class="line">            print(<span class="string">'in A func'</span>)</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">B</span><span class="params">(A)</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">func</span><span class="params">(self)</span>:</span></span><br><span class="line">            <span class="comment"># A.func(self)</span></span><br><span class="line">            super(B,self).func()</span><br><span class="line">            print(<span class="string">'in B func'</span>)</span><br><span class="line"></span><br><span class="line">    obj = B()</span><br><span class="line">    obj.func()</span><br><span class="line"><span class="number">3</span>、多继承</span><br><span class="line">	新式类: 继承object类. C3算法. mro()</span><br><span class="line">    经典类:不继承object类.深度优先</span><br><span class="line"><span class="number">4</span>、继承与抽象：</span><br><span class="line">	抽象即抽取类似或者说比较像的部分</span><br><span class="line">    继承是基于抽象的结果</span><br><span class="line">    抽象只是分析和设计的过程中，一个动作或者说一种技巧，通过抽象可以得到类</span><br><span class="line"><span class="number">5</span>、接口类</span><br><span class="line">	<span class="number">1</span>）继承的两种用途：</span><br><span class="line">    	第一种:继承基类的方法，并且做出自己的改变或者扩展（代码重用）</span><br><span class="line">        第二种：声明某个子类兼容于某基类，定义一个接口类Interface，接口类中定义了一些接口名（就是函数名）且并未实现接口的功能，子类继承接口类，并且实现接口中的功能</span><br><span class="line">     <span class="number">2</span>）实现接口的方式</span><br><span class="line">    <span class="keyword">from</span> abc <span class="keyword">import</span> ABCMeta,abstractmethod</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Payment</span><span class="params">(metaclass=ABCMeta)</span>:</span></span><br><span class="line"><span class="meta">        @abstractmethod</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">pay</span><span class="params">(self,money)</span>:</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">     <span class="number">3</span>）推荐使用接口继承：归一化的设计，</span><br><span class="line"><span class="number">6</span>、抽象类：</span><br><span class="line">	<span class="number">1</span>）抽象类不能被实例化（抽象类与普通类的区别）</span><br></pre></td></tr></table></figure>

<p>5、多肽</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">1、多肽性：</span><br><span class="line">	多个类含有相同的方法，但是执行的效果不一样。</span><br><span class="line">2、鸭子类型：</span><br><span class="line">	看起来像鸭子就是鸭子</span><br><span class="line">3、区别：</span><br><span class="line">	鸭子类型是判断a是不是b</span><br><span class="line">	多肽：a的不同表现形式</span><br></pre></td></tr></table></figure>

<p>6、封装</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、定义：</span><br><span class="line">	隐藏对象的属性和实现细节，仅对外提供公共访问方式。</span><br><span class="line"><span class="number">2</span>、优点：</span><br><span class="line">	将变化隔离；便于使用;提高复用性;提高安全性</span><br><span class="line"><span class="number">3</span>、原则：</span><br><span class="line">	将不需要对外提供的内容都隐藏起来，把属性都隐藏，提供公共方法对其访问</span><br><span class="line"><span class="number">4</span>、私有变量、私有方法：</span><br><span class="line">	在变量前面加`__`</span><br><span class="line">	特点：</span><br><span class="line">		<span class="number">1.</span>类中定义的__x只能在内部使用，如self.__x，引用的就是变形的结果。</span><br><span class="line">		<span class="number">2.</span>这种变形其实正是针对外部的变形，在外部是无法通过__x这个名字访问到的。</span><br><span class="line">		<span class="number">3.</span>在子类定义的__x不会覆盖在父类定义的__x，因为子类中变形成了：_子类名__x,而父类中变形成了：_父类名__x，即双下滑线开头的属性在继承给子类时，子类是无法覆盖的。</span><br><span class="line">    	<span class="number">4.</span>这种机制也并没有真正意义上限制我们从外部直接访问属性，知道了类名和属性名就可以拼出名字：_类名__属性，然后就可以访问了，如a._A__N</span><br><span class="line">   		<span class="number">5.</span>变形的过程只在类的内部生效,在定义后的赋值操作，不会变形</span><br><span class="line"><span class="number">5</span>、封装与扩张型：</span><br><span class="line">	封装在于明确区分内外，使得类实现者可以修改封装内的东西而不影响外部调用者的代码。</span><br><span class="line"><span class="number">6</span>、 property属性</span><br><span class="line">	调用方法时，不需要加括号</span><br><span class="line"><span class="number">7</span>、geter/setter/deleter</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Goods</span>:</span></span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">            <span class="comment"># 原价</span></span><br><span class="line">            self.original_price = <span class="number">100</span></span><br><span class="line">            <span class="comment"># 折扣</span></span><br><span class="line">            self.discount = <span class="number">0.8</span></span><br><span class="line"></span><br><span class="line"><span class="meta">        @property</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">price</span><span class="params">(self)</span>:</span></span><br><span class="line">            <span class="comment"># 实际价格 = 原价 * 折扣</span></span><br><span class="line">            new_price = self.original_price * self.discount</span><br><span class="line">            <span class="keyword">return</span> new_price</span><br><span class="line"><span class="meta">		@price.getter</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">price</span><span class="params">(self, value)</span>:</span></span><br><span class="line">            <span class="keyword">return</span> self.original_price</span><br><span class="line"><span class="meta">        @price.setter</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">price</span><span class="params">(self, value)</span>:</span></span><br><span class="line">            self.original_price = value</span><br><span class="line"><span class="meta">        @price.deleter</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">price</span><span class="params">(self)</span>:</span></span><br><span class="line">            <span class="keyword">del</span> self.original_price</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Foo</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">get_AAA</span><span class="params">(self)</span>:</span></span><br><span class="line">            print(<span class="string">'get的时候运行我啊'</span>)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">set_AAA</span><span class="params">(self,value)</span>:</span></span><br><span class="line">            print(<span class="string">'set的时候运行我啊'</span>)</span><br><span class="line"></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">delete_AAA</span><span class="params">(self)</span>:</span></span><br><span class="line">            print(<span class="string">'delete的时候运行我啊'</span>)</span><br><span class="line">        AAA=property(get_AAA,set_AAA,delete_AAA) <span class="comment">#内置property三个参数与get,set,delete一一对应</span></span><br><span class="line"><span class="number">8</span>、封装的三中形式：</span><br><span class="line">    public：完全对外公开</span><br><span class="line">    protected：对外不公开，对朋友开放</span><br><span class="line">    private：对谁都不开放</span><br><span class="line"><span class="number">9</span>、classmethod、staticmethod：</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    __role = <span class="string">'CHINA'</span></span><br><span class="line"><span class="meta">    @classmethod</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">show_role</span><span class="params">(cls)</span>:</span></span><br><span class="line">        print(cls.__role)</span><br><span class="line"></span><br><span class="line"><span class="meta">    @staticmethod</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_role</span><span class="params">()</span>:</span></span><br><span class="line">        <span class="keyword">return</span> A.__role</span><br></pre></td></tr></table></figure>

<p>7、类的高阶用法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、hasattr、getattr、setattr、delattr</span><br><span class="line">  hasattr:查看对象是否含有属性或方法</span><br><span class="line">  getattr:获取对象的属性或方法  </span><br><span class="line">  setattr：设置对象的属性或方法</span><br><span class="line">  delattr:删除对象的属性或方法</span><br><span class="line"><span class="number">2</span>、__str__,__repr__</span><br><span class="line">	str函数或者print函数---&gt;obj.__str__()</span><br><span class="line">	repr或者交互式解释器---&gt;obj.__repr__()</span><br><span class="line">    %s 触发 __str__</span><br><span class="line">    %r 触发 __repr__</span><br><span class="line">    如果__str__没有被定义,那么就会使用__repr__来代替输出</span><br><span class="line">	注意:这俩方法的返回值必须是字符串,否则抛出异常</span><br><span class="line"><span class="number">3</span>、__getitem__\__setitem__\__delitem__</span><br><span class="line">   __getitem__   <span class="comment">#obj["name"] 触发</span></span><br><span class="line">   __setitem__   <span class="comment">#obj["name"] =“dxl” 触发</span></span><br><span class="line">   __delitem__   <span class="comment">#del obj["name"] 触发</span></span><br><span class="line"><span class="number">4</span>、__del__</span><br><span class="line"> 	析构方法，当对象在内存中被释放时，自动触发执行。<span class="keyword">del</span> obj 时触发 删除对象之前执行</span><br><span class="line"><span class="number">5</span>、__new__ 开辟空间返回self</span><br><span class="line"><span class="number">6</span>、__call__ <span class="comment">#obj()时会触发</span></span><br><span class="line"><span class="number">7</span>、<span class="keyword">with</span> </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__enter__</span><span class="params">(self)</span>:</span></span><br><span class="line">        print(<span class="string">'before'</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__exit__</span><span class="params">(self, exc_type, exc_val, exc_tb)</span>:</span></span><br><span class="line">        print(<span class="string">'after'</span>)</span><br><span class="line">     __enter__ 、__exit__ 同时存在或消失。init 之后执行</span><br><span class="line"><span class="number">8</span>、__hash__ </span><br><span class="line"> <span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        self.a = <span class="number">1</span></span><br><span class="line">        self.b = <span class="number">2</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__hash__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> hash(str(self.a)+str(self.b))</span><br><span class="line"></span><br><span class="line">a = A()</span><br><span class="line">print(hash(a))</span><br><span class="line"><span class="number">9</span>、len </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        self.a = <span class="number">1</span></span><br><span class="line">        self.b = <span class="number">2</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__len__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> len(self.__dict__)</span><br><span class="line">a = A()</span><br><span class="line">print(len(a)) <span class="comment">#2</span></span><br><span class="line"><span class="number">10</span>、eq</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        self.a = <span class="number">1</span></span><br><span class="line">        self.b = <span class="number">2</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__eq__</span><span class="params">(self,obj)</span>:</span></span><br><span class="line">        <span class="keyword">if</span>  self.a == obj.a <span class="keyword">and</span> self.b == obj.b:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">a = A()</span><br><span class="line">b = A()</span><br><span class="line">print(a == b)</span><br></pre></td></tr></table></figure>

<p>10、object 与type的关系</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">python中一切皆对象,类是不是个对象? 大部分类都是type类的对象,包括object类也是type类的对象.</span><br><span class="line">type类 是object类的子类.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#type  instance issubclass</span></span><br><span class="line"><span class="comment">#type instance 判断 对象是不是属于某个类，type不支持继承  instance支持继承</span></span><br><span class="line"><span class="comment"># issubclass  判断某个类与类的关系，是否有继承关系</span></span><br></pre></td></tr></table></figure>

<p>11、如何区分是方法还是函数？</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#只要是隐形传参的就是方法,比如self、cls</span></span><br><span class="line"><span class="comment">#显性传参的就是函数</span></span><br></pre></td></tr></table></figure>

<p>12、实现单例模式的方法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、给类添加装饰器的方式</span><br><span class="line"><span class="number">2</span>、导入模块的方式</span><br><span class="line"><span class="number">3</span>、new的方式</span><br><span class="line"><span class="number">4</span>、原类重写__call__方法</span><br></pre></td></tr></table></figure>

<h2 id="五、网络编程"><a href="#五、网络编程" class="headerlink" title="五、网络编程"></a>五、网络编程</h2><p>1、软件开发架构</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">c/s架构:</span><br><span class="line">	#客户端与服务器端架构</span><br><span class="line">	#qq、微信、网盘、优酷这一类是属于需要安装的桌面应用</span><br><span class="line">B/S架构:</span><br><span class="line">   #浏览器端与服务器端架构</span><br><span class="line">   #百度、知乎、博客园等使用浏览器访问就可以直接使用的应用</span><br><span class="line">所有的B/S架构都是c/s架构，浏览器也是客户端</span><br></pre></td></tr></table></figure>

<p>2、IP地值ip协议</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">规定网络地址的协议叫ip协议，它定义的地址称之为ip地址</span><br><span class="line">a类网   <span class="number">10.0</span><span class="number">.0</span><span class="number">.0</span>~<span class="number">10.255</span><span class="number">.255</span><span class="number">.255</span></span><br><span class="line">b类网   <span class="number">172.16</span><span class="number">.0</span><span class="number">.0</span>~<span class="number">172.31</span><span class="number">.255</span><span class="number">.255</span></span><br><span class="line">c类网   <span class="number">192.168</span><span class="number">.0</span><span class="number">.0</span>~<span class="number">192.168</span><span class="number">.255</span><span class="number">.255</span></span><br><span class="line">ip地址的作用：一个是为每一台计算机分配IP地址，另一个是确定哪些地址在同一个子网络</span><br></pre></td></tr></table></figure>

<p>3、mac地址与arp协议</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mac地址：每块网卡出厂时都被烧制上一个世界唯一的mac地址，长度为48位2进制，通常由12位16进制数表</span><br><span class="line">arp协议：查询IP地址和MAC地址的对应关系.</span><br><span class="line">		是根据IP地址获取物理地址的一个TCP/IP协议</span><br><span class="line">		通过广播和单播完成的</span><br></pre></td></tr></table></figure>

<p>4、子网掩码　</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">172.16.10.1：10101100.00010000.00001010.000000001</span><br><span class="line">255.255.255.0:11111111.11111111.11111111.00000000</span><br><span class="line">AND运算得网络地址结果：10101100.00010000.00001010.000000001-&gt;172.16.10.0</span><br><span class="line"></span><br><span class="line">172.16.10.2：10101100.00010000.00001010.00000010</span><br><span class="line">255255.255.255.0:11111111.11111111.11111111.00000000</span><br><span class="line">AND运算得网络地址结果：10101100.00010000.00001010.000000001-&gt;172.16.10.0</span><br><span class="line">结果都是172.16.10.0，因此它们在同一个子网络。</span><br></pre></td></tr></table></figure>

<p>4、tcp协议</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">三次握手</span><br><span class="line">        <span class="comment"># tcp协议在建立连接的时候经历的过程</span></span><br><span class="line">        <span class="comment"># 第一次由客户端向server端发送Syn请求</span></span><br><span class="line">        <span class="comment"># server端在发送ack回复的时候顺便发送syn请求</span></span><br><span class="line">        <span class="comment"># 客户端收到请求和回复再确认发送一次ack请求</span></span><br><span class="line">        <span class="comment"># 就建立起一个全双工的通信</span></span><br><span class="line">四次挥手</span><br><span class="line">        <span class="comment"># tcp协议 再断开连接的时候经历的过程</span></span><br><span class="line">        <span class="comment"># 第一次由客户端或者server端发起 发送FIN请求</span></span><br><span class="line">        <span class="comment"># 对方回复ack</span></span><br><span class="line">        <span class="comment"># 对方发送fin请求</span></span><br><span class="line">        <span class="comment"># 接收并回复ack</span></span><br><span class="line">        <span class="comment"># 断开了两端的连接</span></span><br></pre></td></tr></table></figure>

<p>5、tcp协议与udp协议的区别：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">TCP---传输控制协议,提供的是面向连接、可靠的字节流服务。当客户和服务器彼此交换数据前，必须先在双方之间建立一个TCP连接，之后才能传输数据。TCP提供超时重发，丢弃重复数据，检验数据，流量控制等功能，保证数据能从一端传到另一端，一对一的，效率低</span><br><span class="line">UDP---用户数据报协议，是一个简单的面向数据报的运输层协议。UDP不提供可靠性，它只是把应用程序传给IP层的数据报发送出去，但是并不能保证它们能到达目的地。由于UDP在传输数据报前不用在客户和服务器之间建立一个连接，且没有超时重发等机制，故而传输速度很快</span><br></pre></td></tr></table></figure>

<p>6、osi模型</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">应用层 （应用层、表示层、会话层）   http https ftp snmp</span><br><span class="line">传输层  四层路由器 四层交换机 tcp udp</span><br><span class="line">网络层      路由器 三层交换机   ip协议</span><br><span class="line">数据链路层  交换机 网卡   arp</span><br><span class="line">物理层     中继器、集线器、</span><br></pre></td></tr></table></figure>

<p>7、socket</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、Socket是应用层与TCP/IP协议族通信的中间软件抽象层</span><br></pre></td></tr></table></figure>

<p>8、手写tcp客户端与服务端</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#服务端</span></span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line">sk = socket.socket()</span><br><span class="line">sk.bind((<span class="string">'127.0.0.1'</span>,<span class="number">8898</span>))  <span class="comment">#把地址绑定到套接字</span></span><br><span class="line">sk.listen()          <span class="comment">#监听链接</span></span><br><span class="line">conn,addr = sk.accept() <span class="comment">#接受客户端链接</span></span><br><span class="line">ret = conn.recv(<span class="number">1024</span>)  <span class="comment">#接收客户端信息</span></span><br><span class="line">print(ret)       <span class="comment">#打印客户端信息</span></span><br><span class="line">conn.send(<span class="string">b'hi'</span>)        <span class="comment">#向客户端发送信息</span></span><br><span class="line">conn.close()       <span class="comment">#关闭客户端套接字</span></span><br><span class="line">sk.close()        <span class="comment">#关闭服务器套接字(可选)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#客户端</span></span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line">sk = socket.socket()           <span class="comment"># 创建客户套接字</span></span><br><span class="line">sk.connect((<span class="string">'127.0.0.1'</span>,<span class="number">8898</span>))    <span class="comment"># 尝试连接服务器</span></span><br><span class="line">sk.send(<span class="string">b'hello!'</span>)</span><br><span class="line">ret = sk.recv(<span class="number">1024</span>)         <span class="comment"># 对话(发送/接收)</span></span><br><span class="line">print(ret)</span><br><span class="line">sk.close()            <span class="comment"># 关闭客户套接字</span></span><br></pre></td></tr></table></figure>

<p>9、基于udp的socket协议;</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#服务端</span></span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line">udp_sk = socket.socket(type=socket.SOCK_DGRAM)   <span class="comment">#创建一个服务器的套接字</span></span><br><span class="line">udp_sk.bind((<span class="string">'127.0.0.1'</span>,<span class="number">9000</span>))        <span class="comment">#绑定服务器套接字</span></span><br><span class="line">msg,addr = udp_sk.recvfrom(<span class="number">1024</span>)</span><br><span class="line">print(msg)</span><br><span class="line">udp_sk.sendto(<span class="string">b'hi'</span>,addr)                 <span class="comment"># 对话(接收与发送)</span></span><br><span class="line">udp_sk.close()                         <span class="comment"># 关闭服务器套接字</span></span><br><span class="line"><span class="comment">#客户后端</span></span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line">ip_port=(<span class="string">'127.0.0.1'</span>,<span class="number">9000</span>)</span><br><span class="line">udp_sk=socket.socket(type=socket.SOCK_DGRAM)</span><br><span class="line">udp_sk.sendto(<span class="string">b'hello'</span>,ip_port)</span><br><span class="line">back_msg,addr=udp_sk.recvfrom(<span class="number">1024</span>)</span><br><span class="line">print(back_msg.decode(<span class="string">'utf-8'</span>),addr)</span><br></pre></td></tr></table></figure>

<p>10、黏包</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">1、成因：tcp是面向流的通信特点、发送方和接受方的缓存机制（发送方的发送不及时，接收方的接受不及时）、</span><br><span class="line">		主要还是因为接收方不知道消息之间的界限，不知道一次性提取多少字节的数据所造成的</span><br><span class="line">2、tcp 会发生黏包，udp会发生丢包</span><br><span class="line">3、解决方案：</span><br><span class="line">		struct模块</span><br><span class="line">		1、先发送struct转换好的数据长度的四个字节</span><br><span class="line">		2、接受方接受4个字节使用struct转换成数字来获取要接收的数据长度</span><br><span class="line">		3、发送方再发送数据</span><br><span class="line">		4、接受方再按照长度接收数据</span><br></pre></td></tr></table></figure>

<p>14、在哪儿使用过tcp协议或udp协议</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">tcp协议：发送邮件</span><br><span class="line">udp协议：及时通信类  cdn</span><br></pre></td></tr></table></figure>

<h2 id="六、并发编程"><a href="#六、并发编程" class="headerlink" title="六、并发编程"></a>六、并发编程</h2><h3 id="6-1概念"><a href="#6-1概念" class="headerlink" title="6.1概念"></a>6.1概念</h3><p>1、进程、线程、协程的特点</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 进程</span></span><br><span class="line">    <span class="comment"># 特点：操作系统级别 开销大 数据隔离</span></span><br><span class="line">         <span class="comment"># 资源分配的最小单位 数据不安全</span></span><br><span class="line">         <span class="comment"># 可以利用多核</span></span><br><span class="line"><span class="comment"># 线程</span></span><br><span class="line">    <span class="comment"># 特点：操作系统级别 开销小 数据共享</span></span><br><span class="line">         <span class="comment"># 被cpu调度的最小单位 数据不安全</span></span><br><span class="line"><span class="comment"># 协程</span></span><br><span class="line">    <span class="comment"># 特点：用户级别  开销极小 数据共享的</span></span><br><span class="line">        <span class="comment"># 不能利用多核 从代码级别来看数据安全</span></span><br></pre></td></tr></table></figure>

<p>2、GIL锁</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、定义：全局解释器锁 ， Cpython解释器下的，导致了同一进程中多个线程不能利用多核，相对安全  </span><br><span class="line"><span class="number">2</span>、为什么要有GIL锁</span><br><span class="line">	gc垃圾回收机制，不想加太多细粒度的锁</span><br></pre></td></tr></table></figure>

<p>3、什么时候用到过进程、线程、协程</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#进程</span></span><br><span class="line">	<span class="number">1</span>、使用什么模块开启进程</span><br><span class="line">    	multprocessing、concurrent.futrues、ProcessPoolExcutor</span><br><span class="line">    <span class="number">2</span>、什么时候使用过进程：</span><br><span class="line">    		爬虫数据分析的时候，自我觉得数据比较多</span><br><span class="line">       为什么要爬虫：</span><br><span class="line">        	买股票，比较哪些股票，一些指标，做数据分析，后来发现数据是不需要爬取的，分析的时候使用padadas更好用一点。</span><br><span class="line"><span class="comment">#线程    </span></span><br><span class="line">	 做wed项目我们使用的框架是django,djanjo默认的就是多线程（在什么地方有)</span><br><span class="line"><span class="comment">#协程</span></span><br><span class="line">	<span class="number">1</span>、使用的模块 gevent asynico:aiohttp sanic</span><br><span class="line">    <span class="number">2</span>、什么时候用过爬虫？</span><br><span class="line">    	研究使用过aiohttp</span><br><span class="line">        web项目 sanic  sayncio</span><br></pre></td></tr></table></figure>

<p>4、线程和协程的区别</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">操作系统控制线程 程序员代码用户控制协程</span><br><span class="line">协程的本质就是一条线程</span><br><span class="line">线程对于IO操作的感知力更强 ：打开文件</span><br><span class="line">协程对于IO操作的感知力弱很多 </span><br><span class="line">协程可以规避打开文件的io,线程不可以</span><br></pre></td></tr></table></figure>

<p>5、进程、线程、协程概念</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">进程：系统进行资源分配和调度的基本单位，执行中的程序</span><br><span class="line">	 进程是动态的、有生命周期的暂时的、程序是静态的长期的软件资料、永久的</span><br><span class="line">线程：CPU调度的最小单位。</span><br><span class="line">协程：协程是一种用户态的轻量级线程，即协程是由用户程序自己控制调度的。</span><br></pre></td></tr></table></figure>

<p>6、进程调度的算法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">先来先服务</span><br><span class="line">短作业优先</span><br><span class="line">时间片轮转</span><br><span class="line">多级反馈</span><br></pre></td></tr></table></figure>

<p>7、并行、并发、同步异步、阻塞、非阻塞</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">并行 : 并行是指两者同时执行</span><br><span class="line">并发 : 并发是指资源有限的情况下，两者交替轮流使用资源，</span><br><span class="line">同步：就是一个任务的完成需要依赖另外一个任务时，只有等待被依赖的任务完成后，依赖的任务才能算完成，这是一种可靠的任务序列</span><br><span class="line">异步：是不需要等待被依赖的任务完成，只是通知被依赖的任务要完成什么工作，依赖的任务也立即执行，只要自己完成了整个任务就算完成了</span><br><span class="line">同步阻塞：效率低的</span><br><span class="line">异步阻塞：阻塞在等待信息</span><br><span class="line">同步非阻塞形式：来回切换</span><br><span class="line">异步  非阻塞形式：效率更高</span><br></pre></td></tr></table></figure>

<p>8、守护进程、守护线程</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#守护进程：</span></span><br><span class="line"><span class="number">1</span>、守护进程会在主进程代码执行结束后就终止</span><br><span class="line"><span class="number">2</span>、护进程内无法再开启子进程</span><br><span class="line">p.daemon=<span class="literal">True</span> <span class="comment">#一定要在p.start()前设置,设置p为守护进程,禁止p创建子进程,并且父进程代码执行结束,p即终止运行</span></span><br><span class="line"><span class="comment">#守护线程</span></span><br><span class="line"><span class="comment">#运行完毕指的是主线程所在的进程内所有非守护线程统统运行完毕，主线程才算运行完毕</span></span><br></pre></td></tr></table></figure>

<p>9、进程间通信</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">队列：</span><br><span class="line">	<span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Process, Queue</span><br><span class="line">	put get empty put_nowait</span><br><span class="line">JoinableQueue:</span><br><span class="line">	<span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Process,JoinableQueue</span><br><span class="line">	put get </span><br><span class="line">	q.task_done() <span class="comment">#使用者使用此方法发出信号，表示q.get()返回的项目已经被处理。如果调用此方法的次数大于从队列中删除的项目数量</span></span><br><span class="line">	q.join() </span><br><span class="line">Manager:数据共享</span><br><span class="line">	<span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Manager,Process,Lock</span><br><span class="line">	<span class="keyword">with</span> Manager() <span class="keyword">as</span> m:</span><br><span class="line">    dic=m.dict(&#123;<span class="string">'count'</span>:<span class="number">100</span>&#125;)</span><br></pre></td></tr></table></figure>

<p>10、线程队列</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、先进先出</span><br><span class="line"><span class="keyword">import</span> queue</span><br><span class="line">q=queue.Queue()</span><br><span class="line"><span class="number">2</span>、先进后出</span><br><span class="line"><span class="keyword">import</span> queue</span><br><span class="line">q=queue.LifoQueue()</span><br><span class="line"><span class="number">3</span>、优先级队列</span><br><span class="line"><span class="keyword">import</span> queue</span><br><span class="line">q=queue.PriorityQueue()</span><br><span class="line">q.put((<span class="number">20</span>,<span class="string">'a'</span>))  <span class="comment">#数字越小，优先级越高</span></span><br></pre></td></tr></table></figure>

<p>11、协程使用过的模块,以及协程的使用</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">greenlet/gevent </span><br><span class="line"><span class="comment">#greenlet</span></span><br><span class="line"><span class="keyword">from</span> greenlet <span class="keyword">import</span> greenlet</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">eat</span><span class="params">(name)</span>:</span></span><br><span class="line">    print(<span class="string">'%s eat 1'</span> %name)</span><br><span class="line">    g2.switch(<span class="string">'egon'</span>)</span><br><span class="line">    print(<span class="string">'%s eat 2'</span> %name)</span><br><span class="line">    g2.switch()</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">play</span><span class="params">(name)</span>:</span></span><br><span class="line">    print(<span class="string">'%s play 1'</span> %name)</span><br><span class="line">    g1.switch()</span><br><span class="line">    print(<span class="string">'%s play 2'</span> %name)</span><br><span class="line"></span><br><span class="line">g1=greenlet(eat)</span><br><span class="line">g2=greenlet(play)</span><br><span class="line"></span><br><span class="line">g1.switch(<span class="string">'egon'</span>)<span class="comment">#可以在第一次switch时传入参数，以后都不需要</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#gevent</span></span><br><span class="line"><span class="keyword">from</span> gevent <span class="keyword">import</span> monkey;monkey.patch_all()</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> gevent</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">eat</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">'eat food 1'</span>)</span><br><span class="line">    time.sleep(<span class="number">2</span>)</span><br><span class="line">    print(<span class="string">'eat food 2'</span>)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">play</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">'play 1'</span>)</span><br><span class="line">    time.sleep(<span class="number">1</span>)</span><br><span class="line">    print(<span class="string">'play 2'</span>)</span><br><span class="line"></span><br><span class="line">g1=gevent.spawn(eat)</span><br><span class="line">g2=gevent.spawn(play)</span><br><span class="line">gevent.joinall([g1,g2])</span><br><span class="line">print(<span class="string">'主'</span>)</span><br></pre></td></tr></table></figure>

<p>5、扩张知识了解</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">C10K ：connect <span class="number">10</span>*<span class="number">1024</span> = <span class="number">1</span>w并发</span><br><span class="line">C10M ：connect <span class="number">10</span>*<span class="number">1024</span>*<span class="number">1024</span> = <span class="number">1000</span>w并发</span><br><span class="line"><span class="comment"># 负载均衡 分布式 celery</span></span><br></pre></td></tr></table></figure>

<p>6、你写代码的时候用到过哪些锁</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">互斥锁（只能acquire一次）</span><br><span class="line">递归锁（可以连续acquire两次</span><br></pre></td></tr></table></figure>

<h3 id="6-2代码"><a href="#6-2代码" class="headerlink" title="6.2代码"></a>6.2代码</h3><p>1、开启进程</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Process</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">f</span><span class="params">(name)</span>:</span></span><br><span class="line">    print(<span class="string">'hello'</span>, name)</span><br><span class="line">    print(<span class="string">'我是子进程'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    p = Process(target=f, args=(<span class="string">'bob'</span>,))</span><br><span class="line">    p.start()</span><br><span class="line">    time.sleep(<span class="number">1</span>)</span><br><span class="line">    print(<span class="string">'执行主进程的内容了'</span>)</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MyProcess</span><span class="params">(Process)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self,name)</span>:</span></span><br><span class="line">        super().__init__()</span><br><span class="line">        self.name=name</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">run</span><span class="params">(self)</span>:</span></span><br><span class="line">        print(os.getpid())</span><br><span class="line">        print(<span class="string">'%s 正在和女主播聊天'</span> %self.name)</span><br><span class="line">p1=MyProcess(<span class="string">'dxl'</span>)</span><br><span class="line">p1.start() </span><br><span class="line">方法：</span><br><span class="line">p.pid  p.name  p.deamen  p.join  [p.join() <span class="keyword">for</span> p <span class="keyword">in</span> p_lst]</span><br></pre></td></tr></table></figure>

<p>2、开启进程加锁</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Process,Lock</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">work</span><span class="params">(lock,n)</span>:</span></span><br><span class="line">    lock.acquire()</span><br><span class="line">    print(<span class="string">'%s: %s is running'</span> % (n, os.getpid()))</span><br><span class="line">    time.sleep(random.random())</span><br><span class="line">    print(<span class="string">'%s: %s is done'</span> % (n, os.getpid()))</span><br><span class="line">    lock.release()</span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    lock=Lock()</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">3</span>):</span><br><span class="line">        p=Process(target=work,args=(lock,i))</span><br><span class="line">        p.start()</span><br></pre></td></tr></table></figure>

<p>3、开启进程池</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Pool</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_page</span><span class="params">(url)</span>:</span></span><br><span class="line">    print(<span class="string">'&lt;进程%s&gt; get %s'</span> %(os.getpid(),url))</span><br><span class="line">    respone=requests.get(url)</span><br><span class="line">    <span class="keyword">if</span> respone.status_code == <span class="number">200</span>:</span><br><span class="line">        <span class="keyword">return</span> &#123;<span class="string">'url'</span>:url,<span class="string">'text'</span>:respone.text&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pasrse_page</span><span class="params">(res)</span>:</span></span><br><span class="line">    print(<span class="string">'&lt;进程%s&gt; parse %s'</span> %(os.getpid(),res[<span class="string">'url'</span>]))</span><br><span class="line">    parse_res=<span class="string">'url:&lt;%s&gt; size:[%s]\n'</span> %(res[<span class="string">'url'</span>],len(res[<span class="string">'text'</span>]))</span><br><span class="line">    <span class="keyword">with</span> open(<span class="string">'db.txt'</span>,<span class="string">'a'</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(parse_res)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    urls=[</span><br><span class="line">        <span class="string">'https://www.baidu.com'</span>,</span><br><span class="line">        <span class="string">'https://www.python.org'</span>,</span><br><span class="line">        <span class="string">'https://www.openstack.org'</span>,</span><br><span class="line">        <span class="string">'https://help.github.com/'</span>,</span><br><span class="line">        <span class="string">'http://www.sina.com.cn/'</span></span><br><span class="line">    ]</span><br><span class="line"></span><br><span class="line">    p=Pool(<span class="number">3</span>)</span><br><span class="line">    res_l=[]</span><br><span class="line">    <span class="keyword">for</span> url <span class="keyword">in</span> urls:</span><br><span class="line">        res=p.apply_async(get_page,args=(url,),callback=pasrse_page)</span><br><span class="line">        res_l.append(res)</span><br><span class="line"></span><br><span class="line">    p.close()</span><br><span class="line">    p.join()</span><br><span class="line">    print([res.get() <span class="keyword">for</span> res <span class="keyword">in</span> res_l]) <span class="comment">#拿到的是get_page的结果,其实完全没必要拿该结果,该结果已经传给回调函数处理了</span></span><br></pre></td></tr></table></figure>

<p>3、开启线程</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> threading <span class="keyword">import</span> Thread</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">sayhi</span><span class="params">(name)</span>:</span></span><br><span class="line">    time.sleep(<span class="number">2</span>)</span><br><span class="line">    print(<span class="string">'%s say hello'</span> %name)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    t=Thread(target=sayhi,args=(<span class="string">'egon'</span>,))</span><br><span class="line">    t.setDaemon(<span class="literal">True</span>) <span class="comment">#必须在t.start()之前设置</span></span><br><span class="line">    t.start()</span><br><span class="line"></span><br><span class="line">    print(<span class="string">'主线程'</span>)</span><br><span class="line">    print(t.is_alive())</span><br><span class="line">    <span class="string">'''</span></span><br><span class="line"><span class="string">    主线程</span></span><br><span class="line"><span class="string">    True</span></span><br><span class="line"><span class="string">    '''</span></span><br></pre></td></tr></table></figure>

<p>4、开启线程使用锁</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">from threading import Thread,Lock</span><br><span class="line">import os,time</span><br><span class="line">def work():</span><br><span class="line">    global n</span><br><span class="line">    lock.acquire()</span><br><span class="line">    temp=n</span><br><span class="line">    time.sleep(0.1)</span><br><span class="line">    n=temp-1</span><br><span class="line">    lock.release()</span><br><span class="line">if __name__ == &apos;__main__&apos;:</span><br><span class="line">    lock=Lock()</span><br><span class="line">    n=100</span><br><span class="line">    l=[]</span><br><span class="line">    for i in range(100):</span><br><span class="line">        p=Thread(target=work)</span><br><span class="line">        l.append(p)</span><br><span class="line">        p.start()</span><br><span class="line">    for p in l:</span><br><span class="line">        p.join()</span><br><span class="line"></span><br><span class="line">    print(n) #结果肯定为0，由原来的并发执行变成串行，牺牲了执行效率保证了数据安全</span><br></pre></td></tr></table></figure>

<p>5、线程池的开启</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">import os</span><br><span class="line">import random</span><br><span class="line">import  time</span><br><span class="line">from concurrent.futures import  ProcessPoolExecutor，ThreadPoolExecutor</span><br><span class="line">def make(i):</span><br><span class="line">    time.sleep(random.uniform(1,3))</span><br><span class="line">    print(f&apos;您好&#123;i&#125;&apos;,os.getpid())</span><br><span class="line">    return i</span><br><span class="line">def call_back(arg):</span><br><span class="line">    print(arg.result())</span><br><span class="line"></span><br><span class="line">if __name__ ==&apos;__main__&apos;:</span><br><span class="line">    p = ProcessPoolExecutor(4)</span><br><span class="line">    l= []</span><br><span class="line">    for i in range(10):</span><br><span class="line">        ret = p.submit(make,i)</span><br><span class="line">        ret.add_done_callback(call_back)# 第一种</span><br><span class="line">        call_back(i)  # 第二种</span><br><span class="line">　　　　　#第三种</span><br><span class="line">　　　　l.append(ret)</span><br><span class="line">　　for i in l:</span><br><span class="line">    　　call_back(i)  #等价于 print(i.result())</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#关于进程池开启回调函数的两种写法</span><br><span class="line">#第一种</span><br><span class="line"></span><br><span class="line">from multiprocessing import Pool</span><br><span class="line">for i in range(10):</span><br><span class="line">    p.apply_async(make,args=(i,),callback=call_back)  不需要resul拿到结果</span><br><span class="line">p.close()</span><br><span class="line">p.join()</span><br><span class="line">#第二种</span><br><span class="line">p=ProcessPoolExecutor(3)</span><br><span class="line">    for url in urls:</span><br><span class="line">        p.submit(make,i).add_done_callback(call_back) #call_back拿到的是一个future对象obj，需要用obj.result()拿到结果，执行结果可参照线程池的。</span><br></pre></td></tr></table></figure>

<p>6、gevent http的请求</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> gevent <span class="keyword">import</span> monkey;monkey.patch_all()</span><br><span class="line"><span class="keyword">import</span> gevent</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_page</span><span class="params">(url)</span>:</span></span><br><span class="line">    print(<span class="string">'GET: %s'</span> %url)</span><br><span class="line">    response=requests.get(url)</span><br><span class="line">    <span class="keyword">if</span> response.status_code == <span class="number">200</span>:</span><br><span class="line">        print(<span class="string">'%d bytes received from %s'</span> %(len(response.text),url))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">start_time=time.time()</span><br><span class="line">gevent.joinall([</span><br><span class="line">    gevent.spawn(get_page,<span class="string">'https://www.python.org/'</span>),</span><br><span class="line">    gevent.spawn(get_page,<span class="string">'https://www.yahoo.com/'</span>),</span><br><span class="line">    gevent.spawn(get_page,<span class="string">'https://github.com/'</span>),</span><br><span class="line">])</span><br><span class="line">stop_time=time.time()</span><br><span class="line">print(<span class="string">'run time is %s'</span> %(stop_time-start_time))</span><br></pre></td></tr></table></figure>

<p>7、aiohttp协程的网络请求</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="七、mysql数据库"><a href="#七、mysql数据库" class="headerlink" title="七、mysql数据库"></a>七、mysql数据库</h2><h3 id="7-1相关概念"><a href="#7-1相关概念" class="headerlink" title="7.1相关概念"></a>7.1相关概念</h3><p>1、为什么要使用数据库</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、操作文件很麻烦，将文件和程序放在一台机器上很不安全</span><br><span class="line"><span class="number">2</span>、数据库的优势;</span><br><span class="line">   程序稳定性 ：这样任意一台服务所在的机器崩溃了都不会影响数据和另外的服务。</span><br><span class="line">　　数据一致性 ：所有的数据都存储在一起，所有的程序操作的数据都是统一的，就不会出现数据不一致的现象</span><br><span class="line">　　并发 ：数据库可以良好的支持并发，所有的程序操作数据库都是通过网络，而数据库本身支持并发的网络操作，不需要我们自己写socket</span><br><span class="line">　　效率 ：使用数据库对数据进行增删改查的效率要高出我们自己处理文件很多</span><br></pre></td></tr></table></figure>

<p>2、相关概念</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1、数据（Data）：描述事物的符号记录</span><br><span class="line">2、数据库（DataBase，简称DB）：数据库即存放数据的仓库，组织文件</span><br><span class="line">3、数据库管理系统（DataBase Management System 简称DBMS）：数据库管理系统，管理数据库</span><br><span class="line">4、数据库服务器：运行数据库管理软件</span><br><span class="line">5、表 ：即文件，用来存放多行内容/多条记录</span><br></pre></td></tr></table></figure>

<p>3、数据库的分类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">关系型：如sqllite，db2，oracle，access，sql server，MySQL，注意：sql语句通用</span><br><span class="line">非关系型：mongodb，redis，memcache</span><br></pre></td></tr></table></figure>

<p>4、sql语句的分类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1、DDL语句 数据库定义语言： 数据库、表、视图、索引、存储过程，例如CREATE DROP ALTER</span><br><span class="line">2、DML语句 数据库操纵语言： 插入数据INSERT、删除数据DELETE、更新数据UPDATE、查询数据SELECT</span><br><span class="line">3、DCL语句 数据库控制语言： 例如控制用户的访问权限GRANT、REVOKE</span><br></pre></td></tr></table></figure>

<p>5、mysql搜索引擎</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">InnoDB</span><br><span class="line">	支持行级所、事务、外键约束</span><br><span class="line">	数据存在硬盘上,两个文件,表结构,(数据和搜索目录)</span><br><span class="line">Memory</span><br><span class="line">  	数据存在内存中,存一个文件,表结构(在硬盘上)</span><br><span class="line">  	数据容易丢失,但读写速度都快</span><br><span class="line">Myisam：</span><br><span class="line">	数据存在硬盘上,存三个文件,表结构,数据,和搜索目录</span><br><span class="line">    既不支持事务、也不支持外键、不支持行级锁</span><br><span class="line">    只支持表锁</span><br><span class="line">    对于只读操作比较多的情况 查询速度相对快</span><br></pre></td></tr></table></figure>

<h2 id="7-2sql语句"><a href="#7-2sql语句" class="headerlink" title="7.2sql语句"></a>7.2sql语句</h2><p>1、dcl语句</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#进入mysql客户端</span></span><br><span class="line">$mysql</span><br><span class="line">mysql&gt; select user();  <span class="comment">#查看当前用户</span></span><br><span class="line">mysql&gt; exit     <span class="comment"># 也可以用\q quit退出</span></span><br><span class="line"><span class="comment"># 默认用户登陆之后并没有实际操作的权限</span></span><br><span class="line"><span class="comment"># 需要使用管理员root用户登陆</span></span><br><span class="line">$ mysql -uroot -p   <span class="comment"># mysql5.6默认是没有密码的</span></span><br><span class="line"><span class="comment">#遇到password直接按回车键</span></span><br><span class="line">mysql&gt; set password = password(<span class="string">'root'</span>); <span class="comment"># 给当前数据库设置密码</span></span><br><span class="line"><span class="comment"># 创建账号</span></span><br><span class="line">mysql&gt; create user <span class="string">'eva'</span>@<span class="string">'192.168.10.%'</span>   IDENTIFIED BY <span class="string">'123'</span>;<span class="comment"># 指示网段</span></span><br><span class="line">mysql&gt; create user <span class="string">'eva'</span>@<span class="string">'192.168.10.5'</span>   <span class="comment"># 指示某机器可以连接</span></span><br><span class="line">mysql&gt; create user <span class="string">'eva'</span>@<span class="string">'%'</span>                    <span class="comment">#指示所有机器都可以连接  </span></span><br><span class="line">mysql&gt; show grants <span class="keyword">for</span> <span class="string">'eva'</span>@<span class="string">'192.168.10.5'</span>;查看某个用户的权限 </span><br><span class="line"><span class="comment"># 远程登陆</span></span><br><span class="line">$ mysql -uroot -p123 -h <span class="number">192.168</span><span class="number">.10</span><span class="number">.3</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 给账号授权</span></span><br><span class="line">mysql&gt; grant all on *.* to <span class="string">'eva'</span>@<span class="string">'%'</span>;</span><br><span class="line">mysql&gt; flush privileges;    <span class="comment"># 刷新使授权立即生效</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建账号并授权</span></span><br><span class="line">mysql&gt; grant all on *.* to <span class="string">'eva'</span>@<span class="string">'%'</span> identified by <span class="string">'123'</span></span><br></pre></td></tr></table></figure>

<p>2、常见sql语句语法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 操作文件夹（库）</span><br><span class="line">   增：create database db1 charset utf8;</span><br><span class="line">   查：show databases;</span><br><span class="line">   改：alter database db1 charset latin1;</span><br><span class="line">   删除: drop database db1;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> 操作文件（表）</span><br><span class="line">   先切换到文件夹下：use db1</span><br><span class="line">   增：create table t1(id int,name char);</span><br><span class="line">   查：show tables;</span><br><span class="line">   改： alter table t1 modify name char(<span class="number">3</span>);</span><br><span class="line">       alter table t1 change name name1 char(<span class="number">2</span>);</span><br><span class="line">   删：drop table t1;</span><br><span class="line">    </span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> 操作文件中的内容（记录）</span><br><span class="line">   增：insert into t1 values(<span class="number">1</span>,<span class="string">'egon1'</span>),(<span class="number">2</span>,<span class="string">'egon2'</span>),(<span class="number">3</span>,<span class="string">'egon3'</span>);</span><br><span class="line">   查：select * <span class="keyword">from</span> t1;</span><br><span class="line">   改：update t1 set name=<span class="string">'sb'</span> where id=<span class="number">2</span>;</span><br><span class="line">   删：delete <span class="keyword">from</span> t1 where id=<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">   清空表：</span><br><span class="line">       delete <span class="keyword">from</span> t1; <span class="comment">#如果有自增id，新增的数据，仍然是以删除前的最后一样作为起始。</span></span><br><span class="line">       truncate table t1;数据量大，删除速度比上一条快，且直接从零开始，</span><br></pre></td></tr></table></figure>

<p>3、表结构</p>
<p>1）创建表</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">create table author2book(</span><br><span class="line">    id int <span class="keyword">not</span> null unique auto_increment,</span><br><span class="line">    author_id int <span class="keyword">not</span> null,</span><br><span class="line">    book_id int <span class="keyword">not</span> null,</span><br><span class="line">    constraint fk_author foreign key(author_id) references author(id)</span><br><span class="line">    on delete cascade</span><br><span class="line">    on update cascade,</span><br><span class="line">    constraint fk_book foreign key(book_id) references book(id)</span><br><span class="line">    on delete cascade</span><br><span class="line">    on update cascade,</span><br><span class="line">    primary key(author_id,book_id)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<p>2）查看表结构</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">desc staff_info</span><br><span class="line">show create table staff_info\G;</span><br></pre></td></tr></table></figure>

<p>3）修改表结构</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">1. 修改表名</span><br><span class="line">      ALTER TABLE 表名 </span><br><span class="line">                      RENAME 新表名;</span><br><span class="line"></span><br><span class="line">2. 增加字段</span><br><span class="line">      ALTER TABLE 表名</span><br><span class="line">                      ADD 字段名  数据类型 [完整性约束条件…],</span><br><span class="line">                      ADD 字段名  数据类型 [完整性约束条件…];</span><br><span class="line">                            </span><br><span class="line">3. 删除字段</span><br><span class="line">      ALTER TABLE 表名 </span><br><span class="line">                      DROP 字段名;</span><br><span class="line"></span><br><span class="line">4. 修改字段</span><br><span class="line">      ALTER TABLE 表名 </span><br><span class="line">                      MODIFY  字段名 数据类型 [完整性约束条件…];</span><br><span class="line">      ALTER TABLE 表名 </span><br><span class="line">                      CHANGE 旧字段名 新字段名 旧数据类型 [完整性约束条件…];</span><br><span class="line">      ALTER TABLE 表名 </span><br><span class="line">                      CHANGE 旧字段名 新字段名 新数据类型 [完整性约束条件…];</span><br><span class="line"></span><br><span class="line">5.修改字段排列顺序/在增加的时候指定字段位置</span><br><span class="line">    ALTER TABLE 表名</span><br><span class="line">                     ADD 字段名  数据类型 [完整性约束条件…]  FIRST;</span><br><span class="line">    ALTER TABLE 表名</span><br><span class="line">                     ADD 字段名  数据类型 [完整性约束条件…]  AFTER 字段名;</span><br><span class="line">    ALTER TABLE 表名</span><br><span class="line">                     CHANGE 字段名  旧字段名 新字段名 新数据类型 [完整性约束条件…]  FIRST;</span><br><span class="line">    ALTER TABLE 表名</span><br><span class="line">                     MODIFY 字段名  数据类型 [完整性约束条件…]  AFTER 字段名;</span><br><span class="line">6、去掉/tianjiaunique约束</span><br><span class="line">	alter table t drop index id;</span><br><span class="line">	alter table t modify id int unique</span><br><span class="line">7、操作主键</span><br><span class="line">	删除主键：</span><br><span class="line">	alter table table_test drop primary key;</span><br><span class="line">	添加主键：</span><br><span class="line">	alter table table_test add primary key(id);</span><br><span class="line">8、操作外键：</span><br><span class="line">	添加外键</span><br><span class="line">	alter table book add constraint fk_id foreign key(press_id) references press(id);</span><br><span class="line">	删除外键</span><br><span class="line">	alter table book drop foreign key fk</span><br></pre></td></tr></table></figure>

<p>4）删除表</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DROP TABLE 表名;</span><br></pre></td></tr></table></figure>

<h3 id="7-3-表纪录操作语法"><a href="#7-3-表纪录操作语法" class="headerlink" title="7.3 表纪录操作语法"></a>7.3 表纪录操作语法</h3><p>1、插入数据</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 插入完整数据（顺序插入）</span><br><span class="line">    语法一：</span><br><span class="line">    INSERT INTO 表名(字段<span class="number">1</span>,字段<span class="number">2</span>,字段<span class="number">3</span>…字段n) VALUES(值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>…值n);</span><br><span class="line"></span><br><span class="line">    语法二：</span><br><span class="line">    INSERT INTO 表名 VALUES (值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>…值n);</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> 指定字段插入数据</span><br><span class="line">    语法：</span><br><span class="line">    INSERT INTO 表名(字段<span class="number">1</span>,字段<span class="number">2</span>,字段<span class="number">3</span>…) VALUES (值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>…);</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> 插入多条记录</span><br><span class="line">    语法：</span><br><span class="line">    INSERT INTO 表名 VALUES</span><br><span class="line">        (值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>…值n),</span><br><span class="line">        (值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>…值n),</span><br><span class="line">        (值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>…值n);</span><br><span class="line">        </span><br><span class="line"><span class="number">4.</span> 插入查询结果</span><br><span class="line">    语法：</span><br><span class="line">    INSERT INTO 表名(字段<span class="number">1</span>,字段<span class="number">2</span>,字段<span class="number">3</span>…字段n) </span><br><span class="line">                    SELECT (字段<span class="number">1</span>,字段<span class="number">2</span>,字段<span class="number">3</span>…字段n) FROM 表<span class="number">2</span></span><br><span class="line">                    WHERE …;</span><br></pre></td></tr></table></figure>

<p>2、更新数据</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">语法：</span><br><span class="line">    UPDATE 表名 SET</span><br><span class="line">        字段1=值1,</span><br><span class="line">        字段2=值2,</span><br><span class="line">        WHERE CONDITION;</span><br><span class="line"></span><br><span class="line">示例：</span><br><span class="line">    UPDATE mysql.user SET password=password(‘123’) </span><br><span class="line">        where user=’root’ and host=’localhost’;</span><br></pre></td></tr></table></figure>

<p>3、删除数据delete</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">语法：</span><br><span class="line">    DELETE FROM 表名 </span><br><span class="line">        WHERE CONITION;</span><br><span class="line"></span><br><span class="line">示例：</span><br><span class="line">    DELETE FROM mysql.user </span><br><span class="line">        WHERE password=’’;</span><br></pre></td></tr></table></figure>

<h3 id="7-4单表操作"><a href="#7-4单表操作" class="headerlink" title="7.4单表操作"></a>7.4单表操作</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#语法</span></span><br><span class="line">SELECT DISTINCT 字段<span class="number">1</span>,字段<span class="number">2.</span>.. FROM 表名</span><br><span class="line">                              WHERE 条件</span><br><span class="line">                              GROUP BY field</span><br><span class="line">                              HAVING 筛选</span><br><span class="line">                              ORDER BY field</span><br><span class="line">                              LIMIT 限制条数</span><br><span class="line"><span class="comment">#优先级</span></span><br><span class="line"><span class="keyword">from</span> where group by  select  distinct  having  order by  limit</span><br><span class="line"><span class="comment">#简单查询</span></span><br><span class="line">distinct concat  <span class="keyword">as</span> case   where   <span class="keyword">in</span>/<span class="keyword">or</span>  like</span><br><span class="line">group </span><br><span class="line">count max min avg sum </span><br><span class="line"></span><br><span class="line"><span class="comment">#limit</span></span><br></pre></td></tr></table></figure>

<h3 id="7-5多表操作"><a href="#7-5多表操作" class="headerlink" title="7.5多表操作"></a>7.5多表操作</h3><p>1、语法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SELECT 字段列表</span><br><span class="line">    FROM 表<span class="number">1</span> INNER|LEFT|RIGHT JOIN 表<span class="number">2</span></span><br><span class="line">    ON 表<span class="number">1.</span>字段 = 表<span class="number">2.</span>字段;</span><br></pre></td></tr></table></figure>

<p>2、其他</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">1、笛卡尔</span><br></pre></td></tr></table></figure>

<p>3、子查询</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#1：子查询是将一个查询语句嵌套在另一个查询语句中。</span><br><span class="line">#2：内层查询语句的查询结果，可以为外层查询语句提供查询条件。</span><br><span class="line">#3：子查询中可以包含：IN、NOT IN、ANY、ALL、EXISTS 和 NOT EXISTS等关键字</span><br><span class="line">#4：还可以包含比较运算符：= 、 !=、&gt; 、&lt;等</span><br></pre></td></tr></table></figure>

<h3 id="7-6数据结构"><a href="#7-6数据结构" class="headerlink" title="7.6数据结构"></a>7.6数据结构</h3><p>1、数据类型</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1、数值  int float DOUBLE DECIMAL</span><br><span class="line">2、日期时间 DATA TIME YESR</span><br><span class="line">3、字符串   char varchar  text LONGBLOB</span><br><span class="line">4、ENUM/set   插入属于enum中的值  set 可以选择多项</span><br></pre></td></tr></table></figure>

<p>2、约束</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">not null</span><br><span class="line">unique  唯一 和联合唯一</span><br><span class="line">primary key  单字段主键、多字段主键</span><br><span class="line">foreign key</span><br><span class="line">default</span><br><span class="line">foreign   foreign key(dpt_id) references department(id)</span><br><span class="line">atuo_increment  offset</span><br></pre></td></tr></table></figure>

<h2 id="八、Mongodb"><a href="#八、Mongodb" class="headerlink" title="八、Mongodb"></a>八、Mongodb</h2><p>1、表的操作</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">db -- 当前使用的数据库 查看名称，代指当前使用的数据库</span><br><span class="line">show databases -- 查看当前服务器磁盘上的所有数据库</span><br><span class="line">use dbname -- 切换当前使用的数据库 或者在内存中创建一个新的数据库 赋值给 db</span><br><span class="line">show tables -- 查看当前数据库中所有磁盘中的表</span><br><span class="line">db.tablename -- 使用当前数据库中的tablename表 在内存中创建表</span><br></pre></td></tr></table></figure>

<p>2、增加</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">db.book.insertOne(&#123;name:<span class="string">'三国演义'</span>&#125;)<span class="comment">#推荐 必须写字典，</span></span><br><span class="line">db.book.insertMany([&#123;name:<span class="string">'睡觉'</span>,age:<span class="string">'19'</span>&#125;,&#123;<span class="string">"anmial"</span>:<span class="string">"dog"</span>&#125;]) <span class="comment">#推荐，必须是列表套字典</span></span><br></pre></td></tr></table></figure>

<p>3、删除</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">db.tablename.deleteOne() <span class="comment"># 删除符合条件的第一条数据</span></span><br><span class="line">db.tablename.deleteMany(&#123;name:<span class="string">'三国演义'</span>&#125;) <span class="comment"># 删除所有符合条件的数据</span></span><br></pre></td></tr></table></figure>

<p>4、查找</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">db.book.find() <span class="comment">#无条件查找:将该表(Collection)中所有的数据一次性返回</span></span><br><span class="line"><span class="comment">#3.2之后加入的</span></span><br><span class="line">db.book.findOne() <span class="comment">#无条件查找一条数据,默认数据库的第一条数据 返回值是json</span></span><br><span class="line">db.book.findOne(&#123;age:<span class="string">'19'</span>&#125;) <span class="comment">#查找一条age等于19的数据,如有多条数据则返回更靠前的数据</span></span><br></pre></td></tr></table></figure>

<p>5、关键字及修改器</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#数学比较符</span></span><br><span class="line">db.student.find(&#123;age:&#123;$gt:<span class="number">21</span>&#125;&#125;)</span><br><span class="line">大于 gt 大于等于 gte lt lte eq ne</span><br><span class="line"><span class="comment">#与update相关的装饰器</span></span><br><span class="line">inc set unset push pushall pul pulall pop </span><br><span class="line"><span class="comment">#and or all in </span></span><br><span class="line">db.student.find(&#123;name:<span class="string">"小兰"</span>,age:<span class="number">30</span>&#125;)</span><br><span class="line">db.student.find(&#123;$<span class="keyword">and</span>:[&#123;name:<span class="string">"小兰"</span>&#125;,&#123;age:<span class="string">"30"</span>&#125;]&#125;)</span><br></pre></td></tr></table></figure>

<p>6、特殊用法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">db.student.update(&#123;name:<span class="string">"火箭队"</span>,<span class="string">'price.count'</span>:&#123;$lt:<span class="number">175</span>&#125;&#125;,&#123;$inc:&#123;<span class="string">'price.$.count'</span>:<span class="number">15</span>&#125;&#125;)</span><br></pre></td></tr></table></figure>

<p>7、limit sort skip</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">db.student.find().skip(<span class="number">1</span>).limit(<span class="number">2</span>).sort(&#123;age:<span class="number">1</span>&#125;)</span><br><span class="line"><span class="comment">#Sort + Skip + Limit 是有执行优先级的 他们的界别分别是 优先 Sort  其次 Skip 最后limit</span></span><br><span class="line"><span class="comment">#Limt Skip + Limit 的优先级 也是先 Skip 再 Limit</span></span><br></pre></td></tr></table></figure>

<p>8、数据类型</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Object  ID ：Documents 自生成的 _id</span><br><span class="line">String： 字符串，必须是utf<span class="number">-8</span></span><br><span class="line">Boolean：布尔值，true 或者false (这里有坑哦~在我们大Python中 <span class="literal">True</span> <span class="literal">False</span> 首字母大写)</span><br><span class="line">Integer：整数 (Int32 Int64 你们就知道有个Int就行了,一般我们用Int32)</span><br><span class="line">Double：浮点数 (没有float类型,所有小数都是Double)</span><br><span class="line">Arrays：数组或者列表，多个值存储到一个键 (list哦,大Python中的List哦)</span><br><span class="line">Object：如果你学过Python的话,那么这个概念特别好理解,就是Python中的字典,这个数据类型就字典</span><br><span class="line">Null：  空数据类型 , 一个特殊的概念,<span class="literal">None</span> Null</span><br><span class="line">Timestamp：时间戳</span><br><span class="line">Date：存储当前日期或时间unix时间格式 (我们一般不用这个Date类型,时间戳可以秒杀一切时间类型)</span><br></pre></td></tr></table></figure>

<h2 id="九、redis-数据库"><a href="#九、redis-数据库" class="headerlink" title="九、redis 数据库"></a>九、redis 数据库</h2><p> 1、启动</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">服务端</span><br><span class="line">redis-server </span><br><span class="line">客户端</span><br><span class="line">redis-cli -p 6380 -h 192.168.16.142</span><br></pre></td></tr></table></figure>

<p>2、基本命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">keys *         查看所有key</span><br><span class="line">type key      查看key类型</span><br><span class="line">expire key seconds    过期时间</span><br><span class="line">ttl key     查看key过期剩余时间        -2表示key已经不存在了</span><br><span class="line">persist     取消key的过期时间   -1表示key存在，没有过期时间</span><br><span class="line"></span><br><span class="line">exists key    判断key存在    存在返回1    否则0</span><br><span class="line">del keys      删除key    可以删除多个</span><br><span class="line">dbsize        算key的数量</span><br></pre></td></tr></table></figure>

<p>3、string</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">set 　　  设置key</span><br><span class="line">get      获取key</span><br><span class="line">append   追加string</span><br><span class="line">mset     设置多个键值对</span><br><span class="line">mget     获取多个键值对</span><br><span class="line">del      删除key</span><br><span class="line">incr     递增+1</span><br><span class="line">decr     递减-1</span><br></pre></td></tr></table></figure>

<p>4、list</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">lpush         从列表左边插</span><br><span class="line">rpush         从列表右边插</span><br><span class="line">lrange          获取一定长度的元素  lrange key  start stop</span><br><span class="line">ltrim               截取一定长度列表</span><br><span class="line">lpop                 删除最左边一个元素</span><br><span class="line">rpop                     删除最右边一个元素</span><br><span class="line">lpushx/rpushx                key存在则添加值，不存在不处理</span><br><span class="line">lpop #删除左边的第一个</span><br><span class="line">rpop #删除右边的第一个</span><br></pre></td></tr></table></figure>

<p>5、sets</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sadd/srem   添加/删除 元素</span><br><span class="line">sismember   判断是否为set的一个元素</span><br><span class="line">smembers    返回集合所有的成员</span><br><span class="line">sdiff             返回一个集合和其他集合的差异</span><br><span class="line">sinter           返回几个集合的交集</span><br><span class="line">sunion          返回几个集合的并集</span><br></pre></td></tr></table></figure>

<p>6、有序集合</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">127.0.0.1:6379&gt; ZADD mid_test 70 &quot;alex&quot;</span><br><span class="line">(integer) 1</span><br><span class="line">127.0.0.1:6379&gt; ZADD mid_test 80 &quot;wusir&quot;</span><br><span class="line">(integer) 1</span><br><span class="line">127.0.0.1:6379&gt; ZADD mid_test 99 &quot;yuyu&quot;</span><br><span class="line">ZRANGE mid_test 0 -1 withscores</span><br></pre></td></tr></table></figure>

<p>7、哈希</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">hset      设置散列值</span><br><span class="line">hget      获取散列值</span><br><span class="line">hmset         设置多对散列值</span><br><span class="line">hmget         获取多对散列值</span><br><span class="line">hsetnx        如果散列已经存在，则不设置（防止覆盖key）</span><br><span class="line">hkeys         返回所有keys</span><br><span class="line">hvals         返回所有values</span><br><span class="line">hlen          返回散列包含域（field）的数量</span><br><span class="line">hdel          删除散列指定的域（field）</span><br><span class="line">hexists       判断是否存在</span><br></pre></td></tr></table></figure>


      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://yoursite.com/2019/09/20/【内容回顾】03-1python基础/" title="python基础">http://yoursite.com/2019/09/20/【内容回顾】03-1python基础/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/dxl/tags/面试题/" rel="tag"># 面试题</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/dxl/2019/09/18/【数据库mogodb】python操作mogodb/" rel="next" title="python操作MongoDB">
                <i class="fa fa-chevron-left"></i> python操作MongoDB
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/dxl/2019/09/20/【面试题】公司的日常/" rel="prev" title="Django">
                Django <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/dxl/images/avatar.png" alt>
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/dxl/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/dxl/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/dxl/tags/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-sign-out"></i>
                我的友链
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="tencent://message/?Menu=yes&uin=1258517737&Site=QQ%E6%9E%81%E5%AE%A2&Service=300&sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45/" title="申请坑位" target="_blank">申请坑位</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、Python基础"><span class="nav-number">1.</span> <span class="nav-text">一、Python基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、函数"><span class="nav-number">2.</span> <span class="nav-text">二、函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1概念"><span class="nav-number">3.</span> <span class="nav-text">2.1概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、模块"><span class="nav-number">4.</span> <span class="nav-text">三、模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、面向对象"><span class="nav-number">5.</span> <span class="nav-text">四、面向对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1概念"><span class="nav-number">6.</span> <span class="nav-text">4.1概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#五、网络编程"><span class="nav-number">7.</span> <span class="nav-text">五、网络编程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#六、并发编程"><span class="nav-number">8.</span> <span class="nav-text">六、并发编程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1概念"><span class="nav-number">8.1.</span> <span class="nav-text">6.1概念</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2代码"><span class="nav-number">8.2.</span> <span class="nav-text">6.2代码</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#七、mysql数据库"><span class="nav-number">9.</span> <span class="nav-text">七、mysql数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1相关概念"><span class="nav-number">9.1.</span> <span class="nav-text">7.1相关概念</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-2sql语句"><span class="nav-number">10.</span> <span class="nav-text">7.2sql语句</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-表纪录操作语法"><span class="nav-number">10.1.</span> <span class="nav-text">7.3 表纪录操作语法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-4单表操作"><span class="nav-number">10.2.</span> <span class="nav-text">7.4单表操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-5多表操作"><span class="nav-number">10.3.</span> <span class="nav-text">7.5多表操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-6数据结构"><span class="nav-number">10.4.</span> <span class="nav-text">7.6数据结构</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#八、Mongodb"><span class="nav-number">11.</span> <span class="nav-text">八、Mongodb</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#九、redis-数据库"><span class="nav-number">12.</span> <span class="nav-text">九、redis 数据库</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-hand-peace-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      本站访客数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      本站总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/dxl/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/dxl/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/dxl/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/dxl/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/dxl/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/dxl/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '13B0JGDuA6ttduN8AQaR8CzF-gzGzoHsz',
        appKey: 'I13r9r5mVgq4jQYpYy6V4gW3',
        placeholder: '欢迎大佬指点~~~',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
